Module: Vend::DeclarativeSetters::ClassMethods
- Defined in:
- lib/vend/modules/declarative_setters.rb
Instance Method Summary collapse
-
#collection_api_path(path = nil) ⇒ Object
Customize the collection api path.
-
#collection_method(name, &block) ⇒ Object
Defines a resource collection method.
-
#collection_methods ⇒ Object
Returns all collection methods.
-
#collection_scope(name, options = {}) ⇒ Object
Defines a resource collection scope.
-
#has_many(name, class_proc) ⇒ Object
The name of a child collection.
-
#has_one(name, class_proc) ⇒ Object
The name of a one to one resource.
-
#path(path = nil) ⇒ Object
The path fragment used for this resource.
-
#resource_api_path(path = nil) ⇒ Object
Customize the resource api path.
Instance Method Details
#collection_api_path(path = nil) ⇒ Object
Customize the collection api path
17 18 19 20 |
# File 'lib/vend/modules/declarative_setters.rb', line 17 def collection_api_path(path=nil) @collection_api_path = path if path @collection_api_path || "#{self.path}s" end |
#collection_method(name, &block) ⇒ Object
Defines a resource collection method
61 62 63 |
# File 'lib/vend/modules/declarative_setters.rb', line 61 def collection_method name, &block collection_methods[name] = block end |
#collection_methods ⇒ Object
Returns all collection methods
66 67 68 |
# File 'lib/vend/modules/declarative_setters.rb', line 66 def collection_methods (@_collection_methods ||= {}) end |
#collection_scope(name, options = {}) ⇒ Object
Defines a resource collection scope
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vend/modules/declarative_setters.rb', line 49 def collection_scope name, = {} default = [:default] || nil collection_method name do |value=default| value = value == false ? "0" : value.to_s current_value = (@parameters ||= {})[name] clear if value != current_value (@parameters ||= {})[name] = value self end end |
#has_many(name, class_proc) ⇒ Object
The name of a child collection.
29 30 31 32 33 34 35 36 |
# File 'lib/vend/modules/declarative_setters.rb', line 29 def has_many(name, class_proc) define_method "#{name}=" do |items| (@_has_many ||= {})[name] = items end define_method name do has_many_reader(name, class_proc) end end |
#has_one(name, class_proc) ⇒ Object
The name of a one to one resource
39 40 41 42 43 44 45 46 |
# File 'lib/vend/modules/declarative_setters.rb', line 39 def has_one(name, class_proc) define_method "#{name}=" do |instance| (@_has_one ||= {})[name] = instance end define_method name do has_one_reader(name, class_proc) end end |
#path(path = nil) ⇒ Object
The path fragment used for this resource
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/vend/modules/declarative_setters.rb', line 4 def path(path = nil) @path = path if path @path || ( self. name. split('::'). last. gsub(/([a-z\d])([A-Z])/,'\1_\2'). downcase ) # Underscored class name end |
#resource_api_path(path = nil) ⇒ Object
Customize the resource api path
23 24 25 26 |
# File 'lib/vend/modules/declarative_setters.rb', line 23 def resource_api_path(path=nil) @resource_api_path = path if path @resource_api_path || "1.0/#{self.path}" end |