idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
9,100
def capture ( name , namespace : nil , segment : nil ) subsegment = begin_subsegment name , namespace : namespace , segment : segment if subsegment . nil? segment = DummySegment . new name : name subsegment = DummySubsegment . new name : name , segment : segment end begin yield subsegment rescue Exception => e subsegme...
Record the passed block as a subsegment . If context_missing is set to LOG_ERROR and no active entity can be found the passed block will be executed as normal but it will not be recorded .
9,101
def metadata ( namespace : :default ) entity = current_entity if entity entity . metadata ( namespace : namespace ) else FacadeMetadata end end
A proxy method to get the metadata under provided namespace from the current active entity .
9,102
def borrow_or_take ( now , borrowable ) @lock . synchronize do reset_new_sec ( now ) if quota_fresh? ( now ) return SamplingDecision :: NOT_SAMPLE if @taken_this_sec >= @quota @taken_this_sec += 1 return SamplingDecision :: TAKE end if borrowable return SamplingDecision :: NOT_SAMPLE if @borrowed_this_sec >= 1 @borrowe...
Decide whether to borrow or take one quota from the reservoir . Return false if it can neither borrow nor take . This method is thread - safe .
9,103
def sample_request? ( sampling_req ) start unless @started now = Time . now . to_i if sampling_req . nil? sampling_req = { service_type : @origin } if @origin elsif ! sampling_req . key? ( :service_type ) sampling_req [ :service_type ] = @origin if @origin end matched_rule = @cache . get_matched_rule ( sampling_req , n...
Return the rule name if it decides to sample based on a service sampling rule matching . If there is no match it will fallback to local defined sampling rules .
9,104
def build ( keys = [ ] ) keys = [ ] if keys . nil? keys = [ keys ] if keys . is_a? Numeric ids = uri . scan ( '%d' ) . count + uri . scan ( '%s' ) . count str = ids > keys . size ? uri . chomp ( '%d' ) . chomp ( '%s' ) . chomp ( '/' ) : uri ( str % keys ) . chomp ( '/' ) end
This takes the
9,105
def login_token ( config : Bigcommerce . config ) payload = { 'iss' => config . client_id , 'iat' => Time . now . to_i , 'jti' => SecureRandom . uuid , 'operation' => 'customer_login' , 'store_hash' => config . store_hash , 'customer_id' => id } JWT . encode ( payload , config . client_secret , 'HS256' ) end
Generate a token that can be used to log the customer into the storefront . This requires your app to have the store_v2_customers_login scope and to be installed in the store .
9,106
def compute_public_path ( source , dir , options = { } ) JasmineRails :: OfflineAssetPaths . disabled ? super : compute_asset_path ( source , options ) end
For Rails 3 . 2 support
9,107
def save_fixture ( file_name , content = rendered ) fixture_path = File . join ( Rails . root , FIXTURE_DIRECTORY , file_name ) fixture_directory = File . dirname ( fixture_path ) FileUtils . mkdir_p fixture_directory unless File . exists? ( fixture_directory ) File . open ( fixture_path , 'w' ) do | file | file . puts...
Saves the rendered as a fixture file .
9,108
def print_line ( obj = "" ) string = obj . to_s string = truncate_to_console_width ( string ) if console_width string = strip_ascii_color ( string ) unless color_enabled? write ( string + "\n" ) output . flush end
Writes to the IO after first truncating the output to fit the console width . If the underlying IO is not a TTY ANSI colors are removed from the output . A newline is always added . Color output can be forced by setting the SSHKIT_COLOR environment variable .
9,109
def init_reporters Spinach . config [ :reporter_classes ] . each do | reporter_class | reporter_options = default_reporter_options . merge ( Spinach . config . reporter_options ) reporter = Support . constantize ( reporter_class ) . new ( reporter_options ) reporter . bind end end
Initializes the runner with a parsed feature
9,110
def run require_dependencies require_frameworks init_reporters suite_passed = true Spinach . hooks . run_before_run features_to_run . each do | feature | feature_passed = FeatureRunner . new ( feature , orderer : orderer ) . run suite_passed &&= feature_passed break if fail_fast? && ! feature_passed end Spinach . hooks...
Runs this runner and outputs the results in a colorful manner .
9,111
def orderer @orderer ||= Support . constantize ( Spinach . config [ :orderer_class ] ) . new ( seed : Spinach . config . seed ) end
The orderer for this run .
9,112
def parse_from_file parsed_opts = YAML . load_file ( config_path ) parsed_opts . delete_if { | k | k . to_s == 'config_path' } parsed_opts . each_pair { | k , v | self [ k ] = v } true rescue Errno :: ENOENT false end
Parse options from the config file
9,113
def on_tag ( tag ) before_scenario do | scenario , step_definitions | tags = scenario . tags next unless tags . any? yield ( scenario , step_definitions ) if tags . include? tag . to_s end end
Runs before running a scenario with a particular tag
9,114
def get_feature_and_defs ( file ) feature = Parser . open_file ( file ) . parse [ feature , Spinach . find_step_definitions ( feature . name ) ] end
Get the feature and its definitions from the appropriate files
9,115
def step_missing? ( step , step_defs ) method_name = Spinach :: Support . underscore step . name return true unless step_defs . respond_to? ( method_name ) used_steps << step_defs . step_location_for ( step . name ) . join ( ':' ) false end
Process a step from the feature file using the given step_defs . If it is missing return true . Otherwise add it to the used_steps for the report at the end and return false .
9,116
def store_unused_steps ( names , step_defs ) names . each do | name | location = step_defs . step_location_for ( name ) . join ( ':' ) unused_steps [ location ] = name end end
Store any unused step names for the report at the end of the audit
9,117
def step_names_for_class ( klass ) klass . ancestors . map { | a | a . respond_to? ( :steps ) ? a . steps : [ ] } . flatten end
Get the step names for all steps in the given class including those in common modules
9,118
def report_unused_steps used_steps . each { | location | unused_steps . delete location } unused_steps . each do | location , name | puts "\n" + "Unused step: #{location} " . colorize ( :yellow ) + "'#{name}'" . colorize ( :light_yellow ) end end
Produce a report of unused steps that were not found anywhere in the audit
9,119
def report_missing_steps ( steps ) puts "\nMissing steps:" . colorize ( :light_cyan ) steps . each do | step | puts Generators :: StepGenerator . new ( step ) . generate . gsub ( / / , ' ' ) . colorize ( :cyan ) end end
Print a report of the missing step objects provided
9,120
def bind Spinach . hooks . tap do | hooks | hooks . before_run { | * args | before_run ( * args ) } hooks . after_run { | * args | after_run ( * args ) } hooks . before_feature { | * args | before_feature_run ( * args ) } hooks . after_feature { | * args | after_feature_run ( * args ) } hooks . on_undefined_feature { |...
Hooks the reporter to the runner endpoints
9,121
def feature_files files_to_run = [ ] @args . each do | arg | if arg . match ( / \. / ) if File . exists? arg . gsub ( / \d / , '' ) files_to_run << arg else fail! "#{arg} could not be found" end elsif File . directory? ( arg ) files_to_run << Dir . glob ( File . join ( arg , '**' , '*.feature' ) ) elsif arg != "{}" fai...
Uses given args to list the feature files to run . It will find a single feature features in a folder and subfolders or every feature file in the feature path .
9,122
def parse_options config = { } begin OptionParser . new do | opts | opts . on ( '-c' , '--config_path PATH' , 'Parse options from file (will get overriden by flags)' ) do | file | Spinach . config [ :config_path ] = file end opts . on ( '-b' , '--backtrace' , 'Show backtrace of errors' ) do | show_backtrace | config [ ...
Parses the arguments into options .
9,123
def run_with_fallbacks ( commands , options = { } ) commands . each do | command | result = run_command ( command , options ) return result if result . success? end SshConnection :: ExecResult . new ( 1 ) end
Runs commands from the specified array until successful . Returns the result of the successful command or an ExecResult with exit_code 1 if all fail .
9,124
def run ( * args ) session , run_in_tx = session_and_run_in_tx_from_args ( args ) fail ArgumentError , 'Expected a block to run in Transaction.run' unless block_given? return yield ( nil ) unless run_in_tx tx = Neo4j :: Transaction . new ( session ) yield tx rescue Exception => e tx . mark_failed unless tx . nil? raise...
Runs the given block in a new transaction .
9,125
def session_and_run_in_tx_from_args ( args ) fail ArgumentError , 'Too few arguments' if args . empty? fail ArgumentError , 'Too many arguments' if args . size > 2 if args . size == 1 fail ArgumentError , 'Session must be specified' if ! args [ 0 ] . is_a? ( Neo4j :: Core :: CypherSession ) [ args [ 0 ] , true ] else [...
To support old syntax of providing run_in_tx first But session first is ideal
9,126
def << ( entry ) if index = @cache [ entry ] entries [ index ] = entry else @cache [ entry ] = size entries << entry end self end
Add or update an entry in the set
9,127
def []= ( name , entry ) warn "#{self.class}#[]= is deprecated. Use #{self.class}#<< instead: #{caller.first}" raise "#{entry.class} is not added with the correct name" unless name && name . to_s == entry . name . to_s self << entry entry end
Make sure that entry is part of this PropertySet
9,128
def update ( other ) other_options = if kind_of? ( other . class ) return self if self . eql? ( other ) assert_valid_other ( other ) other . options else other = other . to_hash return self if other . empty? other end @options = @options . merge ( other_options ) . freeze assert_valid_options ( @options ) normalize = D...
Updates the Query with another Query or conditions
9,129
def filter_records ( records ) records = records . uniq if unique? records = match_records ( records ) if conditions records = sort_records ( records ) if order records = limit_records ( records ) if limit || offset > 0 records end
Takes an Enumerable of records and destructively filters it . First finds all matching conditions then sorts it then does offset & limit
9,130
def match_records ( records ) conditions = self . conditions records . select { | record | conditions . matches? ( record ) } end
Filter a set of records by the conditions
9,131
def sort_records ( records ) sort_order = order . map { | direction | [ direction . target , direction . operator == :asc ] } records . sort_by do | record | sort_order . map do | ( property , ascending ) | Sort . new ( record_value ( record , property ) , ascending ) end end end
Sorts a list of Records by the order
9,132
def slice! ( * args ) offset , limit = extract_slice_arguments ( * args ) if self . limit || self . offset > 0 offset , limit = get_relative_position ( offset , limit ) end update ( :offset => offset , :limit => limit ) end
Slices collection by adding limit and offset to the query so a single query is executed
9,133
def inspect attrs = [ [ :repository , repository . name ] , [ :model , model ] , [ :fields , fields ] , [ :links , links ] , [ :conditions , conditions ] , [ :order , order ] , [ :limit , limit ] , [ :offset , offset ] , [ :reload , reload? ] , [ :unique , unique? ] , ] "#<#{self.class.name} #{attrs.map { |key, value| ...
Returns detailed human readable string representation of the query
9,134
def condition_properties properties = Set . new each_comparison do | comparison | next unless comparison . respond_to? ( :subject ) subject = comparison . subject properties << subject if subject . kind_of? ( Property ) end properties end
Get the properties used in the conditions
9,135
def to_subquery collection = model . all ( merge ( :fields => model_key ) ) Conditions :: Operation . new ( :and , Conditions :: Comparison . new ( :in , self_relationship , collection ) ) end
Transform Query into subquery conditions
9,136
def to_hash { :repository => repository . name , :model => model . name , :fields => fields , :links => links , :conditions => conditions , :offset => offset , :limit => limit , :order => order , :unique => unique? , :add_reversed => add_reversed? , :reload => reload? , } end
Hash representation of a Query
9,137
def assert_valid_options ( options ) options = options . to_hash options . each do | attribute , value | case attribute when :fields then assert_valid_fields ( value , options [ :unique ] ) when :links then assert_valid_links ( value ) when :conditions then assert_valid_conditions ( value ) when :offset then assert_val...
Validate the options
9,138
def assert_valid_offset ( offset , limit ) unless offset >= 0 raise ArgumentError , "+options[:offset]+ must be greater than or equal to 0, but was #{offset.inspect}" end if offset > 0 && limit . nil? raise ArgumentError , '+options[:offset]+ cannot be greater than 0 if limit is not specified' end end
Verifies that query offset is non - negative and only used together with limit
9,139
def assert_valid_other ( other ) other_repository = other . repository repository = self . repository other_class = other . class unless other_repository == repository raise ArgumentError , "+other+ #{other_class} must be for the #{repository.name} repository, not #{other_repository.name}" end other_model = other . mod...
Verifies that associations given in conditions belong to the same repository as query s model
9,140
def merge_conditions ( conditions ) @conditions = Conditions :: Operation . new ( :and ) << @conditions unless @conditions . nil? conditions . compact! conditions . each do | condition | case condition when Conditions :: AbstractOperation , Conditions :: AbstractComparison add_condition ( condition ) when Hash conditio...
Handle all the conditions options provided
9,141
def append_condition ( subject , bind_value , model = self . model , operator = :eql ) case subject when Property , Associations :: Relationship then append_property_condition ( subject , bind_value , operator ) when Symbol then append_symbol_condition ( subject , bind_value , model , operator ) when String then append...
Append conditions to this Query
9,142
def set_operation ( operation , other ) assert_valid_other ( other ) query = self . class . new ( @repository , @model , other . to_relative_hash ) query . instance_variable_set ( :@conditions , other_conditions ( other , operation ) ) query end
Apply a set operation on self and another query
9,143
def other_conditions ( other , operation ) self_conditions = query_conditions ( self ) unless self_conditions . kind_of? ( Conditions :: Operation ) operation_slug = case operation when :intersection , :difference then :and when :union then :or end self_conditions = Conditions :: Operation . new ( operation_slug , self...
Return the union with another query s conditions
9,144
def query_conditions ( query ) if query . limit || query . links . any? query . to_subquery else query . conditions end end
Extract conditions from a Query
9,145
def self_relationship @self_relationship ||= begin model = self . model Associations :: OneToMany :: Relationship . new ( :self , model , model , self_relationship_options ) end end
Return a self referrential relationship
9,146
def self_relationship_options keys = model_key . map { | property | property . name } repository = self . repository { :child_key => keys , :parent_key => keys , :child_repository_name => repository . name , :parent_repository_name => repository . name , } end
Return options for the self referrential relationship
9,147
def get ( * key ) assert_valid_key_size ( key ) repository = self . repository key = self . key ( repository . name ) . typecast ( key ) repository . identity_map ( self ) [ key ] || first ( key_conditions ( repository , key ) . update ( :order => nil ) ) end
Grab a single record by its key . Supports natural and composite key lookups as well .
9,148
def first ( * args ) first_arg = args . first last_arg = args . last limit_specified = first_arg . kind_of? ( Integer ) with_query = ( last_arg . kind_of? ( Hash ) && ! last_arg . empty? ) || last_arg . kind_of? ( Query ) limit = limit_specified ? first_arg : 1 query = with_query ? last_arg : { } query = self . query ....
Return the first Resource or the first N Resources for the Model with an optional query
9,149
def copy ( source_repository_name , target_repository_name , query = { } ) target_properties = properties ( target_repository_name ) query [ :fields ] ||= properties ( source_repository_name ) . select do | property | target_properties . include? ( property ) end repository ( target_repository_name ) do | repository | ...
Copy a set of records from one repository to another .
9,150
def repository_name context = Repository . context context . any? ? context . last . name : default_repository_name end
Get the current + repository_name + for this Model .
9,151
def finalize_allowed_writer_methods @allowed_writer_methods = public_instance_methods . map { | method | method . to_s } . grep ( WRITER_METHOD_REGEXP ) . to_set @allowed_writer_methods -= INVALID_WRITER_METHODS @allowed_writer_methods . freeze end
Initialize the list of allowed writer methods
9,152
def assert_valid_properties repository_name = self . repository_name if properties ( repository_name ) . empty? && ! relationships ( repository_name ) . any? { | relationship | relationship . kind_of? ( Associations :: ManyToOne :: Relationship ) } raise IncompleteModelError , "#{name} must have at least one property o...
Test if the model has properties
9,153
def [] ( name ) name = name . to_s entries . detect { | entry | entry . name . to_s == name } end
Lookup an entry in the SubjectSet based on a given name
9,154
def reload ( other_query = Undefined ) query = self . query query = other_query . equal? ( Undefined ) ? query . dup : query . merge ( other_query ) identity_map = repository . identity_map ( model ) loaded_entries . each do | resource | identity_map [ resource . key ] = resource end properties = self . properties fiel...
Reloads the Collection from the repository
9,155
def get ( * key ) assert_valid_key_size ( key ) key = model_key . typecast ( key ) query = self . query @identity_map [ key ] || if ! loaded? && ( query . limit || query . offset > 0 ) lazy_load @identity_map [ key ] else first ( model . key_conditions ( repository , key ) . update ( :order => nil ) ) end end
Lookup a Resource in the Collection by key
9,156
def all ( query = Undefined ) if query . equal? ( Undefined ) || ( query . kind_of? ( Hash ) && query . empty? ) dup else new_collection ( scoped_query ( query ) ) end end
Returns a new Collection optionally scoped by + query +
9,157
def first ( * args ) first_arg = args . first last_arg = args . last limit_specified = first_arg . kind_of? ( Integer ) with_query = ( last_arg . kind_of? ( Hash ) && ! last_arg . empty? ) || last_arg . kind_of? ( Query ) limit = limit_specified ? first_arg : 1 query = with_query ? last_arg : { } query = self . query ....
Return the first Resource or the first N Resources in the Collection with an optional query
9,158
def at ( offset ) if loaded? || partially_loaded? ( offset ) super elsif offset == 0 first elsif offset > 0 first ( :offset => offset ) elsif offset == - 1 last else last ( :offset => offset . abs - 1 ) end end
Lookup a Resource from the Collection by offset
9,159
def slice! ( * args ) removed = super resources_removed ( removed ) unless removed . nil? compact! if RUBY_VERSION <= '1.8.6' unless removed . kind_of? ( Enumerable ) return removed end offset , limit = extract_slice_arguments ( * args ) query = sliced_query ( offset , limit ) new_collection ( query , removed ) end
Deletes and Returns the Resources given by an offset or a Range
9,160
def []= ( * args ) orphans = Array ( superclass_slice ( * args [ 0 .. - 2 ] ) ) resources = resources_added ( super ) resources_removed ( orphans - loaded_entries ) resources end
Splice a list of Resources at a given offset or range
9,161
def each return to_enum unless block_given? super do | resource | begin original , resource . collection = resource . collection , self yield resource ensure resource . collection = original end end end
Iterate over each Resource
9,162
def new ( attributes = { } ) resource = repository . scope { model . new ( attributes ) } self << resource resource end
Initializes a Resource and appends it to the Collection
9,163
def update ( attributes ) assert_update_clean_only ( :update ) dirty_attributes = model . new ( attributes ) . dirty_attributes dirty_attributes . empty? || all? { | resource | resource . update ( attributes ) } end
Update every Resource in the Collection
9,164
def update! ( attributes ) assert_update_clean_only ( :update! ) model = self . model dirty_attributes = model . new ( attributes ) . dirty_attributes if dirty_attributes . empty? true else dirty_attributes . each do | property , value | property . assert_valid_value ( value ) end unless _update ( dirty_attributes ) re...
Update every Resource in the Collection bypassing validation
9,165
def destroy! repository = self . repository deleted = repository . delete ( self ) if loaded? unless deleted == size return false end each do | resource | resource . persistence_state = Resource :: PersistenceState :: Immutable . new ( resource ) end clear else mark_loaded end true end
Remove all Resources from the repository bypassing validation
9,166
def respond_to? ( method , include_private = false ) super || model . respond_to? ( method ) || relationships . named? ( method ) end
Check to see if collection can respond to the method
9,167
def partially_loaded? ( offset , limit = 1 ) if offset >= 0 lazy_possible? ( head , offset + limit ) else lazy_possible? ( tail , offset . abs ) end end
Test if the collection is loaded between the offset and limit
9,168
def lazy_load if loaded? return self end mark_loaded head = self . head tail = self . tail query = self . query resources = repository . read ( query ) resources -= head if head . any? resources -= tail if tail . any? resources -= @removed . to_a if @removed . any? query . add_reversed? ? unshift ( * resources . revers...
Lazy loads a Collection
9,169
def new_collection ( query , resources = nil , & block ) if loaded? resources ||= filter ( query ) end self . class . new ( query , resources , & block ) end
Initializes a new Collection
9,170
def set_operation ( operation , other ) resources = set_operation_resources ( operation , other ) other_query = Query . target_query ( repository , model , other ) new_collection ( query . send ( operation , other_query ) , resources ) end
Apply a set operation on self and another collection
9,171
def _create ( attributes , execute_hooks = true ) resource = repository . scope { model . send ( execute_hooks ? :create : :create! , default_attributes . merge ( attributes ) ) } self << resource if resource . saved? resource end
Creates a resource in the collection
9,172
def _save ( execute_hooks = true ) loaded_entries = self . loaded_entries loaded_entries . each { | resource | set_default_attributes ( resource ) } @removed . clear loaded_entries . all? { | resource | resource . __send__ ( execute_hooks ? :save : :save! ) } end
Saves a collection
9,173
def default_attributes return @default_attributes if @default_attributes default_attributes = { } conditions = query . conditions if conditions . slug == :and model_properties = properties . dup model_key = self . model_key if model_properties . to_set . superset? ( model_key . to_set ) model_properties -= model_key en...
Returns default values to initialize new Resources in the Collection
9,174
def resource_added ( resource ) resource = initialize_resource ( resource ) if resource . saved? @identity_map [ resource . key ] = resource @removed . delete ( resource ) else set_default_attributes ( resource ) end resource end
Track the added resource
9,175
def resources_added ( resources ) if resources . kind_of? ( Enumerable ) resources . map { | resource | resource_added ( resource ) } else resource_added ( resources ) end end
Track the added resources
9,176
def resources_removed ( resources ) if resources . kind_of? ( Enumerable ) resources . each { | resource | resource_removed ( resource ) } else resource_removed ( resources ) end end
Track the removed resources
9,177
def filter ( other_query ) query = self . query fields = query . fields . to_set unique = other_query . unique? if other_query . links . empty? && ( unique || ( ! unique && ! query . unique? ) ) && ! other_query . reload? && ! other_query . raw? && other_query . fields . to_set . subset? ( fields ) && other_query . con...
Filter resources in the collection based on a Query
9,178
def scoped_query ( query ) if query . kind_of? ( Query ) query . dup else self . query . relative ( query ) end end
Return the absolute or relative scoped query
9,179
def delegate_to_model ( method , * args , & block ) model = self . model model . send ( :with_scope , query ) do model . send ( method , * args , & block ) end end
Delegate the method to the Model
9,180
def read ( query ) return [ ] unless query . valid? query . model . load ( adapter . read ( query ) , query ) end
Retrieve a collection of results of a query
9,181
def update ( attributes , collection ) return 0 unless collection . query . valid? && attributes . any? adapter . update ( attributes , collection ) end
Update the attributes of one or more resource instances
9,182
def delete ( descendant ) @descendants . delete ( descendant ) each { | d | d . descendants . delete ( descendant ) } end
Remove a descendant
9,183
def valid? ( value , negated = false ) dumped_value = dump ( value ) if required? && dumped_value . nil? negated || false else value_dumped? ( dumped_value ) || ( dumped_value . nil? && ( allow_nil? || negated ) ) end end
Test the value to see if it is a valid value for this Property
9,184
def assert_valid_value ( value ) unless valid? ( value ) raise Property :: InvalidValueError . new ( self , value ) end true end
Asserts value is valid
9,185
def attribute_set ( name , value ) property = properties [ name ] if property value = property . typecast ( value ) self . persistence_state = persistence_state . set ( property , value ) end end
Sets the value of the attribute and marks the attribute as dirty if it has been changed so that it may be saved . Do not set from instance variables directly but use this method . This method handles the lazy loading the property and returning of defaults if nessesary .
9,186
def attributes ( key_on = :name ) attributes = { } lazy_load ( properties ) fields . each do | property | if model . public_method_defined? ( name = property . name ) key = case key_on when :name then name when :field then property . field else property end attributes [ key ] = __send__ ( name ) end end attributes end
Gets all the attributes of the Resource instance
9,187
def inspect attrs = properties . map do | property | value = if new? || property . loaded? ( self ) property . get! ( self ) . inspect else '<not loaded>' end "#{property.instance_variable_name}=#{value}" end "#<#{model.name} #{attrs.join(' ')}>" end
Compares another Resource for equality
9,188
def dirty_attributes dirty_attributes = { } original_attributes . each_key do | property | next unless property . respond_to? ( :dump ) dirty_attributes [ property ] = property . dump ( property . get! ( self ) ) end dirty_attributes end
Hash of attributes that have unsaved changes
9,189
def initialize_copy ( original ) instance_variables . each do | ivar | instance_variable_set ( ivar , DataMapper :: Ext . try_dup ( instance_variable_get ( ivar ) ) ) end self . persistence_state = persistence_state . class . new ( self ) end
Initialize a new instance of this Resource using the provided values
9,190
def reset_key properties . key . zip ( key ) do | property , value | property . set! ( self , value ) end end
Reset the key to the original value
9,191
def clear_subjects model_properties = properties ( model_properties - model_properties . key | relationships ) . each do | subject | next unless subject . loaded? ( self ) remove_instance_variable ( subject . instance_variable_name ) end end
Remove all the ivars for properties and relationships
9,192
def eager_load ( properties ) unless properties . empty? || key . nil? || collection . nil? properties . each { | property | property . set! ( self , nil ) } collection . reload ( :fields => properties ) end self end
Reloads specified attributes
9,193
def conditions key = self . key if key model . key_conditions ( repository , key ) else conditions = { } properties . each do | property | next unless property . loaded? ( self ) conditions [ property ] = property . get! ( self ) end conditions end end
Return conditions to match the Resource
9,194
def child_relationships child_relationships = [ ] relationships . each do | relationship | next unless relationship . respond_to? ( :collection_for ) set_default_value ( relationship ) next unless relationship . loaded? ( self ) child_relationships << relationship end many_to_many , other = child_relationships . partit...
Returns loaded child relationships
9,195
def save_self ( execute_hooks = true ) return saved? unless dirty_self? if execute_hooks new? ? create_with_hooks : update_with_hooks else _persist end clean? end
Saves the resource
9,196
def save_parents ( execute_hooks ) run_once ( true ) do parent_relationships . map do | relationship | parent = relationship . get ( self ) if parent . __send__ ( :save_parents , execute_hooks ) && parent . __send__ ( :save_self , execute_hooks ) relationship . set ( self , parent ) end end . all? end end
Saves the parent resources
9,197
def dirty_self? if original_attributes . any? true elsif new? ! model . serial . nil? || properties . any? { | property | property . default? } else false end end
Checks if the resource has unsaved changes
9,198
def dirty_parents? run_once ( false ) do parent_associations . any? do | association | association . __send__ ( :dirty_self? ) || association . __send__ ( :dirty_parents? ) end end end
Checks if the parents have unsaved changes
9,199
def cmp? ( other , operator ) return false unless repository . send ( operator , other . repository ) && key . send ( operator , other . key ) if saved? && other . saved? dirty_attributes == other . dirty_attributes else properties . all? do | property | __send__ ( property . name ) . send ( operator , other . __send__...
Return true if + other + s is equivalent or equal to + self + s