Module: HyperResource::Modules::InternalAttributes::ClassMethods

Defined in:
lib/hyper_resource/modules/internal_attributes.rb

Instance Method Summary collapse

Instance Method Details

#_hr_attributesObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 28

def _hr_attributes
  [ :root,
    :href,
    :request,
    :response,
    :body,
    :attributes,
    :links,
    :objects,
    :loaded
  ]
end

#_hr_class_attribute(*names) ⇒ Object

Inheritable class attribute, kinda like in Rails.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 43

def _hr_class_attribute(*names)
  names.map(&:to_sym).each do |name|
    instance_eval <<-EOT
      def #{name}=(val)
        @#{name} = val
      end
      def #{name}
        return @#{name} if defined?(@#{name})
        return superclass.#{name} if superclass.respond_to?(:#{name})
        nil
      end
    EOT
  end
end

#_hr_class_attributesObject



23
24
25
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 23

def _hr_class_attributes
  [ :root ]
end

#_hr_fallback_attribute(*names) ⇒ Object

Instance attributes which fall back to class attributes.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 60

def _hr_fallback_attribute(*names)
  names.map(&:to_sym).each do |name|
    class_eval <<-EOT
      def #{name}=(val)
        @#{name} = val
      end
      def #{name}
        return @#{name} if defined?(@#{name})
        return self.class.#{name} if self.class.respond_to?(:#{name})
        nil
      end
    EOT
  end
end