Module: PDC::Resource::Attributes

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/pdc/resource/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



92
93
94
95
96
97
98
99
# File 'lib/pdc/resource/attributes.rb', line 92

def method_missing(name, *args, &block)
  if association?(name) then association(name).load
  elsif attribute?(name) then attribute(name)
  elsif predicate?(name)   then predicate(name)
  elsif setter?(name)      then set_attribute(name, args.first)
  else super
  end
end

Instance Method Details

#[]=(name, value) ⇒ Object



78
79
80
# File 'lib/pdc/resource/attributes.rb', line 78

def []=(name, value)
  set_attribute(name, value)
end

#attributes=(new_attributes) ⇒ Object



73
74
75
76
# File 'lib/pdc/resource/attributes.rb', line 73

def attributes=(new_attributes)
  @attributes ||= AttributeStore.new
  use_setters(new_attributes) if new_attributes
end

#initialize(attributes = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



67
68
69
70
71
# File 'lib/pdc/resource/attributes.rb', line 67

def initialize(attributes = {})
  self.attributes = attributes
  @uri_template = scoped.uri
  yield(self) if block_given?
end

#inspectObject



82
83
84
# File 'lib/pdc/resource/attributes.rb', line 82

def inspect
  "#<#{self.class}(#{@uri_template}) id: #{id.inspect} #{inspect_attributes}>"
end