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

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

Instance Method Summary collapse

Instance Method Details

#_hr_attributesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 33

def _hr_attributes # @private
  [ :root,
    :href,
    :auth,
    :headers,
    :namespace,
    :adapter,
    :faraday_options,

    :request,
    :response,
    :body,

    :attributes,
    :links,
    :objects,

    :loaded
  ]
end

#_hr_class_attribute(*names) ⇒ Object

Inheritable class attribute, kinda like in Rails.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 55

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

#_hr_class_attributesObject



23
24
25
26
27
28
29
30
31
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 23

def _hr_class_attributes # @private
  [ :root,             ## e.g. 'https://example.com/api/v1'
    :auth,             ## e.g. {:basic => ['username', 'password']}
    :headers,          ## e.g. {'Accept' => 'application/vnd.example+json'}
    :namespace,        ## e.g. 'ExampleAPI', or the class ExampleAPI itself
    :adapter,          ## subclass of HR::Adapter
    :faraday_options   ## e.g. {:request => {:timeout => 30}}
  ]
end

#_hr_fallback_attribute(*names) ⇒ Object

Instance attributes which fall back to class attributes.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/hyper_resource/modules/internal_attributes.rb', line 71

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