Module: Fleakr::Support::Object::ClassMethods
- Defined in:
- lib/fleakr/support/object.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #find_all(condition, options) ⇒ Object
- #find_one(condition, options) ⇒ Object
- #flickr_attribute(name, options = {}) ⇒ Object
- #has_many(*attributes) ⇒ Object
- #lazily_load(*attributes) ⇒ Object
- #scoped_search ⇒ Object
Instance Method Details
#attributes ⇒ Object
7 8 9 |
# File 'lib/fleakr/support/object.rb', line 7 def attributes @attributes ||= [] end |
#find_all(condition, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fleakr/support/object.rb', line 31 def find_all(condition, ) attribute = [:using].nil? ? condition.to_s.sub(/^by_/, '') : [:using] target_class = [:class_name].nil? ? self.name : "Fleakr::Objects::#{options[:class_name]}" class_eval " def self.find_all_\#{condition}(value, options = {})\n options.merge!(:\#{attribute} => value)\n \n response = Fleakr::Api::MethodRequest.with_response!('\#{options[:call]}', options)\n (response.body/'rsp/\#{options[:path]}').map {|e| \#{target_class}.new(e) }\n end\n CODE\nend\n" |
#find_one(condition, options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fleakr/support/object.rb', line 45 def find_one(condition, ) attribute = [:using].nil? ? condition.to_s.sub(/^by_/, '') : [:using] class_eval " def self.find_\#{condition}(value, options = {})\n options.merge!(:\#{attribute} => value)\n \n response = Fleakr::Api::MethodRequest.with_response!('\#{options[:call]}', options)\n \#{self.name}.new(response.body)\n end\n CODE\nend\n" |
#flickr_attribute(name, options = {}) ⇒ Object
11 12 13 14 |
# File 'lib/fleakr/support/object.rb', line 11 def flickr_attribute(name, = {}) self.attributes << Attribute.new(name, [:from]) class_eval "attr_accessor :#{name}" end |
#has_many(*attributes) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fleakr/support/object.rb', line 16 def has_many(*attributes) = attributes. class_name = self.name attributes.each do |attribute| target = "Fleakr::Objects::#{attribute.to_s.classify}" finder_attribute = [:using].nil? ? "#{class_name.demodulize.underscore}_id": [:using] class_eval " def \#{attribute}\n @\#{attribute} ||= \#{target}.send(\"find_all_by_\#{finder_attribute}\".to_sym, self.id)\n end\n CODE\n end\nend\n" |
#lazily_load(*attributes) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fleakr/support/object.rb', line 68 def lazily_load(*attributes) = attributes. attributes.each do |attribute| class_eval " def \#{attribute}_with_loading\n self.send(:\#{options[:with]}) if @\#{attribute}.nil?\n \#{attribute}_without_loading\n end\n alias_method_chain :\#{attribute}, :loading\n CODE\n end\nend\n" |
#scoped_search ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/fleakr/support/object.rb', line 58 def scoped_search key = "#{self.name.demodulize.underscore.downcase}_id".to_sym class_eval " def search(search_text)\n Fleakr::Objects::Search.new(:text => search_text, :\#{key} => self.id).results\n end\n CODE\nend\n" |