Module: RestfulObjects::ObjectMacros

Defined in:
lib/restful_objects/domain_model/mixins/object_macros.rb

Instance Method Summary collapse

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, options = {})
  RestfulObjects::DomainModel.current.types[self.name].register_action(name.to_s, options)
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, options = {})
  type = type.name if type.is_a?(Class)

  RestfulObjects::DomainModel.current.types[self.name].register_collection(name.to_s, type, options)

  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, options = {})
  RestfulObjects::DomainModel.current.types[self.name].register_property(name.to_s, type, options)

  define_method(name) do
    instance_variable_get("@#{name}")
  end

  unless options[:read_only]
    define_method("#{name}=") do |value|
      if options[:max_length] && value && value.length > options[:max_length]
        raise ArgumentError.new("string max length exceeded")
      end
      instance_variable_set("@#{name}", value)
    end
  end
end