Module: Resource::ClassMethods
- Defined in:
- lib/simplespotify/resource/class_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_constant(name) ⇒ Object
- #_template ⇒ Object
- #many(name, o = {}) ⇒ Object
- #merge(name) ⇒ Object
- #one(name, o = {}) ⇒ Object
- #prop(name, o = {}) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
4 5 6 |
# File 'lib/simplespotify/resource/class_methods.rb', line 4 def self.extended(base) super base end |
Instance Method Details
#_constant(name) ⇒ Object
44 45 46 |
# File 'lib/simplespotify/resource/class_methods.rb', line 44 def _constant name "#{name}".gsub(/s$/, '').split('_').map(&:capitalize).join.to_sym end |
#_template ⇒ Object
40 41 42 |
# File 'lib/simplespotify/resource/class_methods.rb', line 40 def _template @_template end |
#many(name, o = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/simplespotify/resource/class_methods.rb', line 15 def many name, o={} attr_accessor name.to_sym kind = o[:kind] || name @_template[name] = { type: :resource_collection, kind: _constant(kind), from: name, paginated: o[:paginated] || false } end |
#merge(name) ⇒ Object
36 37 38 |
# File 'lib/simplespotify/resource/class_methods.rb', line 36 def merge name @_template[name] = {type: :virtual, from: name} end |
#one(name, o = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/simplespotify/resource/class_methods.rb', line 26 def one name, o={} attr_accessor name.to_sym kind = o[:kind] || name @_template[name] = { type: :resource, kind: _constant(kind), from: (o[:from] || name) } end |
#prop(name, o = {}) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/simplespotify/resource/class_methods.rb', line 8 def prop name, o={} p = (o[:from] || name) p = {type: :real, from: p, default: o[:default]} if o[:default] @_template[name] = p attr_accessor name.to_sym end |