Module: OAuth2::Attributes::ClassMethods
- Defined in:
- lib/oauth2/attributes.rb
Instance Method Summary collapse
-
#attribute(handle) ⇒ Object
Defines a callback for a handle.
- #attributes(*handles) ⇒ Object
Instance Method Details
#attribute(handle) ⇒ Object
Defines a callback for a handle.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/oauth2/attributes.rb', line 22 def attribute(handle) attribute_names << handle.to_sym class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{handle}(&block) @attributes ||= {} if block_given? @attributes[:#{handle}] = block return end if @attributes.key?(:#{handle}) value = @attributes[:#{handle}] value.is_a?(Proc) ? value.call : value else raise "No attribute or callback for '#{handle}' defined" end end def #{handle.to_s.gsub('?', '')}=(value) @attributes ||= {} @attributes[:#{handle}] = value end EOS end |
#attributes(*handles) ⇒ Object
49 50 51 52 53 |
# File 'lib/oauth2/attributes.rb', line 49 def attributes(*handles) handles.each do |handle| attribute(handle) end end |