How to use finder_args method of ClassMethods Package

Best Howitzer_ruby code snippet using ClassMethods.finder_args

orm.rb

Source:orm.rb Github

copy

Full Screen

...41 # The API limits its length to no more then 50 charactors. If the class itself is the42 # target, this value will either not be set or set to nil. The reader should MUST return43 # nil in this case.44 #45 # finder_args [Array]: A possibly complex array of valuse that will be paseed to the46 # finder method in order to retrieve the target instance. The API spesifies that the47 # array and all subelements must impliment the #to_yaml and #to_json method in48 # addation to being Marshalable. If the class itself is the49 # target, this value will either not be set or set to nil. The reader should MUST return50 # nil in this case.51 #52 # method [String]: The method to be sent to the target instance. The API limits this value53 # to 50 charictars. It MAY NOT be nil or empty.54 #55 # method_args [Array]: A possibly complex array of values to pass to the spesified method of56 # the target instance. It must be marshalable. The ORM layer is responcible to Marshal.dump57 # and Marshal.load these values.58 #59 # name [String]: If the ORM impliments the +for+ method, then it MUST store a name which the60 # API spesifies SHOULD be unique per target. The ORM SHOULD NOT enforce this restriction, but61 # MAY assume it. ORM's that do not impliment +for+ must none the less have a #name= method62 # that returns the value passed to it (as is normal with setter methods) and must not raise an error63 # when a hash of values includes name. It must also respond to the name method with nil. When64 # inplimented, name may be no longer then 255 characters.65 #66 # persistant [Boolean]: if this value is set to true a worker will not call destroy after running the job.67 # If it is nil or not set it may be assumed to be false, and ORM may return nil instead of false in this68 # case.69 #70 # == Chained Jobs71 #72 # Chained Jobs are run after a job and allow for various function to take place such as logging and73 # error handleing. There are three(3) categories for chaining :failure, :success, and :ensure. The74 # ORM must impliment a getter and setter for each as described below. This version does not75 # inpliment it, but ORMs should be be designed in such a way that :prior and :instead chains can be76 # added in future version of this API.77 # 78 # === Getters: 79 # getters should return an array of structures (Struct or equivelent) representing the chained jobs80 # for this job. The structure should have three(3) members and MAY be read-only.81 #82 # caller: An instance of the ORM class for the job in question (i.e. self)83 #84 # target: An instance of the ORM class for the chained job85 #86 # params: a Hash or other object that will be substituted for the special value '__params__' when calling87 # the target job.88 #89 # The object returned may have other methods and functionality. Clients SHOULD NOT antisipate or use90 # these methods.91 # 92 # === Setters:93 # setters must accept five(5) differnt types of input. Except as described below setters are NOT distructive,94 # that is job.failure=logme adds logme to the list of failure jobs and does not remove jobs that may have previously95 # been chained. Clients should call save after using the setter to write the changes to disk96 #97 # ORM or Updater::Update: Add this job to the chain, with no parameters. Updater::Update#orm will give the job.98 #99 # Array<ORM or Updater::Update>: Add each job in the array to the chain100 #101 # Hash(<ORM or Updater::Update>, params): Add the keys to the chain with the valuse as params. Clients102 # should note that it is not possible to add multiple calls to the same job using this method.103 #104 # nil: remove all jobs from this chain. Clients Note, that this is the only way to remove a previously added105 # job from a chain.106 class Base107 108 # Every ORM should set this constant to a symbol that matches the most109 # obvious method used to retrive a known instance. :get or :find are likely110 # candidates. 111 FINDER= nil112 113 # every ORM should set this to a method when called on an object producted by114 # that ORM will give a value that can be passed to the FINDER method to retrieve115 # the object from the datastore. :id, _id, or :key are likely candidates116 ID = nil117 118 # Workers will call this method on a job before running it to insure that in the case119 # of multiple workers hiting the same queue only one will run the job. The worker 120 # MUST pass itself to Lock, and the implimentation MAY use the name of the worker121 # to identify who has locked this job. 122 #123 # If a worker is successfully able to lock this job, or has already locked the Job, this 124 # method MUST return a true value. If a lock was unsuccessful, it MUST return the125 # value false, and MAY use the 'say' method of the suplied worker to explain why a lock126 # could not be aquired.127 def lock(worker)128 NotImplementedError129 end130 131 #write any changes made to the job back to the datastore.132 def save133 NotImplementedError134 end135 136 #Remove this job from the datastore.137 def destroy138 NotImplementedError139 end140 141 end142 143 class ClassMethods144 145 # When passed the value returned by the #id method of a job, this method must return146 # that job from the datastore.147 def get(id)148 NotImplementedError149 end150 151 # The hash keys are symbols for the one of the 12 field values listed in the intro to the 152 # ORM::Base class. The values are the actual values that should be returned by the 153 # accessor methods. Depending on the datastore some values may need to be marshaled154 # converted, etc.. before being written to the datastore.155 def create(hash)156 NotImplementedError157 end158 159 # This method returns all jobs that are now ready to run, that is thier time valuse is less160 # then or equal to the value returned by calling now on the registered time class (tnow).161 def current162 NotImplementedError163 end164 165 # Returns a count of how many jobs are currently ready to run.166 def current_load167 NotImplementedError168 end169 170 # Runurns a count of the number of jobs scheduled to run at a later time, that is there171 # time value is strictly greater then the value returned by calling now on the registered 172 # time class(tnow)173 def delayed174 NotImplementedError175 end176 177 # Returns a count of how may jobs are curently scheduled between start and finish seconds 178 # from now. e.g future(0,60) would tell you how many jobs will run in the next minute. This179 # function is used to adjust the number of workers needed as well as for monitering.180 def future(start, finish)181 NotImplementedError182 end183 184 # Returns the number os seconds until the next job will be ready to run. If there are no185 # Jobs in the queue it returns nil, if there is at least one job ready to run it MUST return186 # 0. This may be an apporximation or the value may be cached for brief periods to improve187 # datastore performance.188 def queue_time189 NotImplementedError190 end191 192 # Locks to a worker and returns a job that is ready to run. Workers will call this when they are193 # ready for another job. In general it should lock jobs in the order they were recieved or scheduled,194 # but strict ordering is not a requirement. (c.f. delayed_job). If there are current jobs, this method195 # MUST return one which has been locked successfully, internally trying successive current jobs if 196 # the first one fails to lock. It MUST NOT raise an error or return nil if the datastore is temerarly 197 # busy. Instead it must wait until it can either get access to and lock a record, or prove that no jobs198 # are current.199 #200 # In the event that there are no current jobs left in the datastore this method should retunr nil. The201 # should inturperate this as a sign that the queue is empty and consult +queue_time+ to determine202 # how long to wait for the next job.203 def lock_next(worker)204 NotImplementedError205 end206 207 # This method unlocks and makes availible any and all jobs which have been locked by the worker.208 # Workers are uniquely identified by the +name+ method. This is an indication that the worker has209 # died or been killed and cannot complete its job.210 def clear_locks(worker)211 NotImplementedError212 end213 214 # Compleatly remove all jobs and associeted data from the datastore including chained215 # Methods.216 def clear_all217 NotImplementedError218 end219 220 # This method is the generic way to setup the datastore. Options is a hash one of whose fields221 # will be :logger, the logger instance to pass on to the ORM. The rest of the options are ORM 222 # spesific. The function should prepair a connection to the datastore using the given options.223 # If the connection cannot be prepaired then an appropriate error should be raised.224 def setup(options)225 NotImplementedError 226 end227 228 # This method is called by the child before a fork call. It allows the ORM to clean up any connections229 # Made by the parent and establish new connections if necessary.230 def before_fork231 232 end233 234 def after_fork235 236 end237 238 # Optional, but strongly recomended.239 #240 # For any datastore that permits, return and Array of all delayed, chained, and current but not locked jobs that reference 241 # mytarget, myfinder, and myfinder_args, that is they clearly have the spesified Target. Optionally, limit the result to 242 # return the first job that also has a name value of myname. The name value is spesified as unique per target so the 243 # which record is returned in the case that multiple jobs fro the same target share the same name is undefined.244 def for(mytarget, myfinder, myfinder_args, myname=nil)245 NotImplementedError246 end247 248 private249 250 #Short hand method that retruns the current time value that this queue is using.251 def tnow252 Updater::Update.time.now.to_i253 end254 255 end256 end...

Full Screen

Full Screen

section_dsl.rb

Source:section_dsl.rb Github

copy

Full Screen

...37 # @note If anonymous section uses, then inline selector should be specified.38 # Otherwise arguments should be defined with `.me` dsl method in named section39 # @return [Array]40 # @raise [ArgumentError] when finder arguments were not specified41 def finder_args42 return @args if @args.present?43 @finder_args ||= (section_class.default_finder_args || raise(ArgumentError, 'Missing finder arguments'))44 end45 # Returns selector options for the section.46 # @note If anonymous section uses, then inline selector should be specified.47 # Otherwise arguments should be defined with `.me` dsl method in named section48 # @return [Array]49 # @raise [ArgumentError] when finder arguments were not specified50 def finder_options51 @options if @args.present? # it is ok to have blank options, so we rely here on the argments52 @finder_options ||= (section_class.default_finder_options || {})53 end54 end55 protected56 # DSL method which defines named or anonymous section within a page or a section57 # @note This method generates following dynamic methods:58 #59 # <b><em>section_name</em>_section</b> - equals capybara #find(...) method60 #61 # <b><em>section_name</em>_sections</b> - equals capybara #all(...) method62 #63 # <b><em>section_name</em>_sections.first</b> - equals capybara #first(...) method64 #65 # <b>has_<em>section_name</em>_section?</b> - equals capybara #has_selector(...) method66 #67 # <b>has_no_<em>section_name</em>_section?</b> - equals capybara #has_no_selector(...) method68 # @note It is possible to use nested anonymous sections69 # @param name [Symbol, String] an unique section name70 # @param args [Array] original Capybara arguments. For details, see `Capybara::Node::Finders#all.71 # (In most cases should be ommited for named sections because the section selector is specified72 # with `#me` method. But must be specified for anonymous sections)73 # @param options [Hash] original Capybara options. For details, see `Capybara::Node::Finders#all.74 # (In most cases should be ommited for named sections because the section selector is specified75 # with `#me` method. But may be specified for anonymous sections)76 # @param block [Proc] this block can contain nested sections and elements77 # @example Named section78 # class MenuSection < Howitzer::Web::Section79 # me :xpath, ".//*[@id='panel']"80 # end81 # class HomePage < Howitzer::Web::Page82 # section :menu83 # end84 # HomePage.on { is_expected.to have_menu_section }85 # @example Anonymous section86 # class HomePage < Howitzer::Web::Page87 # section :info_panel, '#panel' do88 # element :edit_button, '.edit'89 # element :title_field, '.title'90 #91 # def edit_info(title: nil)92 # edit_button_element.click93 # title_field_element.set(title)94 # end95 # end96 # end97 # HomePage.on { info_panel.edit_info(title: 'Test Title') }98 # @example Anonymous nested section99 # class HomePage < Howitzer::Web::Page100 # section :info_panel, '#panel' do101 # element :edit_button, '.edit'102 #103 # section :form, '.form' do104 # element :title_field, '.title'105 # end106 # end107 # end108 # HomePage.on { info_panel_section.edit_info(title: 'Test Title') }109 # @!visibility public110 def section(name, *args, **options, &block)111 scope = SectionScope.new(name, *args, **options, &block)112 define_section_method(scope.section_class, name, *scope.finder_args, **scope.finder_options)113 define_sections_method(scope.section_class, name, *scope.finder_args, **scope.finder_options)114 define_has_section_method(name, *scope.finder_args, **scope.finder_options)115 define_has_no_section_method(name, *scope.finder_args, **scope.finder_options)116 end117 private118 def define_section_method(klass, name, *args, **options)119 define_method("#{name}_section") do |**block_options|120 kwdargs = options.transform_keys(&:to_sym).merge(block_options.transform_keys(&:to_sym))121 if kwdargs.present?122 klass.new(self, capybara_context.find(*args, **kwdargs))123 else124 klass.new(self, capybara_context.find(*args))125 end126 end127 end128 def define_sections_method(klass, name, *args, **options)129 define_method("#{name}_sections") do |**block_options|...

Full Screen

Full Screen

finder_args

Using AI Code Generation

copy

Full Screen

1 def finder_args(*args)2 def self.find_by(*args)3 find(*finder_args(*args))4 def self.find_by_name(name)5 find_by(:name => name)6person = Person.find_by_name("John Doe")7 def self.find_by_name_and_age(name, age)8 find_by(:name => name, :age => age)9person = Person.find_by_name_and_age("John Doe", 30)10 def self.find_by_name_or_age(name, age)11 find_by(:name => name, :age => age)12person = Person.find_by_name_or_age("John Doe", 30)13 def self.find_by_name_or_age(name, age)14 find_by(:name => name) || find_by(:age => age)15person = Person.find_by_name_or_age("John Doe", 30)16person = Person.find_by_name_or_age("Jane Doe", 30)17person = Person.find_by_name_or_age("Jane Doe", 40)18 def self.find_by_name_or_age(name, age)19 find_by(:name => name) || find_by(:age => age)20person = Person.find_by_name_or_age("John Doe", 30)21person = Person.find_by_name_or_age("Jane Doe

Full Screen

Full Screen

finder_args

Using AI Code Generation

copy

Full Screen

1 def finder_args(*args)2 def self.find_by(*args)3 find(*finder_args(*args))4 def self.find_by_name(name)5 find_by(:name => name)6person = Person.find_by_name("John Doe")7 def self.find_by_name_and_age(name, age)8 find_by(:name => name, :age => age)9person = Person.find_by_name_and_age("John Doe", 30)10 def self.find_by_name_or_age(name, age)11 find_by(:name => name, :age => age)12person = Person.find_by_name_or_age("John Doe", 30)13 def self.find_by_name_or_age(name, age)14 find_by(:name => name) || find_by(:age => age)15person = Person.find_by_name_or_age("John Doe", 30)16person = Person.find_by_name_or_age("Jane Doe", 30)17person = Person.find_by_name_or_age("Jane Doe", 40)18 def self.find_by_name_or_age(name, age)19 find_by(:name => name) || find_by(:age => age)20person = Person.find_by_name_or_age("John Doe", 30)21person = Person.find_by_name_or_age("Jane Doe

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful