Module: RestfulObjects::ObjectMacros
- Defined in:
- lib/restful_objects/domain_model/mixins/object_macros.rb
Instance Method Summary collapse
- #action(name, options = {}) ⇒ Object
- #collection(name, type, options = {}) ⇒ Object
- #property(name, type, options = {}) ⇒ Object
Instance Method Details
#action(name, options = {}) ⇒ Object
27 28 29 |
# File 'lib/restful_objects/domain_model/mixins/object_macros.rb', line 27 def action(name, = {}) RestfulObjects::DomainModel.current.types[self.name].register_action(name.to_s, ) end |
#collection(name, type, options = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/restful_objects/domain_model/mixins/object_macros.rb', line 19 def collection(name, type, = {}) type = type.name if type.is_a?(Class) RestfulObjects::DomainModel.current.types[self.name].register_collection(name.to_s, type, ) attr_reader(name) end |
#property(name, type, options = {}) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/restful_objects/domain_model/mixins/object_macros.rb', line 2 def property(name, type, = {}) RestfulObjects::DomainModel.current.types[self.name].register_property(name.to_s, type, ) define_method(name) do instance_variable_get("@#{name}") end unless [:read_only] define_method("#{name}=") do |value| if [:max_length] && value && value.length > [:max_length] raise ArgumentError.new("string max length exceeded") end instance_variable_set("@#{name}", value) end end end |