Module: Plaza::RestfulModel::ClassMethods

Defined in:
lib/plaza/models/restful_model.rb

Instance Method Summary collapse

Instance Method Details

#adapterObject



37
38
39
# File 'lib/plaza/models/restful_model.rb', line 37

def adapter
  Plaza::RestfulAdapter.new(self)
end

#allObject



29
30
31
# File 'lib/plaza/models/restful_model.rb', line 29

def all
  collection(adapter.index)
end

#create(attributes) ⇒ Object



41
42
43
44
# File 'lib/plaza/models/restful_model.rb', line 41

def create(attributes)
  resource = self.new(attributes)
  resource.save && resource
end

#find(id) ⇒ Object



33
34
35
# File 'lib/plaza/models/restful_model.rb', line 33

def find(id)
  self.new( adapter.show(id) )
end

#has_many(*relations) ⇒ Object

Class Configuration



60
61
62
63
64
65
66
# 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) ⇒ Object Also known as: plaza_config=



68
69
70
71
# File 'lib/plaza/models/restful_model.rb', line 68

def plaza_config(config = nil)
  @plaza_config ||= :default
  config ? @plaza_config = config : @plaza_config
end

#plural_nameObject



50
51
52
# File 'lib/plaza/models/restful_model.rb', line 50

def plural_name
  Inflector.pluralize(singular_name)
end

#singular_nameObject



54
55
56
# 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) ⇒ Object



46
47
48
# File 'lib/plaza/models/restful_model.rb', line 46

def where(attributes)
  collection( adapter.index(attributes) )
end