module Plaza::RestfulModel::ClassMethods
Public Instance Methods
adapter()
click to toggle source
# File lib/plaza/models/restful_model.rb, line 37 def adapter Plaza::RestfulAdapter.new(self) end
all()
click to toggle source
# File lib/plaza/models/restful_model.rb, line 29 def all collection(adapter.index) end
create(attributes)
click to toggle source
# File lib/plaza/models/restful_model.rb, line 41 def create(attributes) resource = self.new(attributes) resource.save && resource end
find(id)
click to toggle source
# File lib/plaza/models/restful_model.rb, line 33 def find(id) self.new( adapter.show(id) ) end
has_many(*relations)
click to toggle source
Class Configuration
# File lib/plaza/models/restful_model.rb, line 60 def has_many(*relations) relations.each do |r| define_method(sym = has_many_symbol_for(r)) do class_for(r).collection(adapter.has_many(self.id,sym)) end end end
plaza_config(config = nil)
click to toggle source
# File lib/plaza/models/restful_model.rb, line 68 def plaza_config(config = nil) @plaza_config ||= :default config ? @plaza_config = config : @plaza_config end
Also aliased as: plaza_config=
plural_name()
click to toggle source
# File lib/plaza/models/restful_model.rb, line 50 def plural_name Inflector.pluralize(singular_name) end
singular_name()
click to toggle source
# File lib/plaza/models/restful_model.rb, line 54 def singular_name self.to_s.split('::').last.scan(/[A-Z][a-z]+/).join('_').downcase end
where(attributes)
click to toggle source
# File lib/plaza/models/restful_model.rb, line 46 def where(attributes) collection( adapter.index(attributes) ) end
Private Instance Methods
has_many_symbol_for(identifier)
click to toggle source
# File lib/plaza/models/restful_model.rb, line 77 def has_many_symbol_for(identifier) if identifier.kind_of? Class identifier.plural_name elsif identifier.kind_of? String Inflector.tableize(identifier.split('::').last) elsif identifier.kind_of? Symbol identifier else raise TypeError.new("Can't convert to has_many symbol") end end