Class: ResourceKitling::Resource
- Inherits:
-
Object
- Object
- ResourceKitling::Resource
- Defined in:
- lib/resource_kitling.rb
Direct Known Subclasses
Freefeed::Archive, Freefeed::Attachment, Freefeed::Bookmarklet, Freefeed::Comment, Freefeed::Group, Freefeed::Invitation, Freefeed::Notification, Freefeed::Password, Freefeed::Post, Freefeed::Request, Freefeed::Search, Freefeed::Session, Freefeed::Stat, Freefeed::Summary, Freefeed::Timeline, Freefeed::User
Class Attribute Summary collapse
-
._actions ⇒ Object
Returns the value of attribute _actions.
-
.subclasses ⇒ Object
readonly
Returns the value of attribute subclasses.
Class Method Summary collapse
Instance Method Summary collapse
- #actions ⇒ Object
-
#initialize ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize ⇒ Resource
Returns a new instance of Resource.
99 100 |
# File 'lib/resource_kitling.rb', line 99 def initialize end |
Class Attribute Details
._actions ⇒ Object
Returns the value of attribute _actions.
56 57 58 |
# File 'lib/resource_kitling.rb', line 56 def _actions @_actions end |
.subclasses ⇒ Object (readonly)
Returns the value of attribute subclasses.
57 58 59 |
# File 'lib/resource_kitling.rb', line 57 def subclasses @subclasses end |
Class Method Details
.actions(&block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/resource_kitling.rb', line 65 def self.actions(&block) self._actions ||= ActionCollection.new if block_given? self._actions.instance_eval(&block) self._actions.each do |action| if respond_to?(action.name.to_sym) raise( ArgumentError, "Action '#{action.name}' is already defined on `#{self}`" ) end method_block = method_for_action(action) send(:define_singleton_method, action.name, &method_block) end end self._actions end |
.inherited(subclass) ⇒ Object
58 59 60 61 62 |
# File 'lib/resource_kitling.rb', line 58 def inherited(subclass) superclass.inherited(subclass) if superclass.respond_to?(:inherited) @subclasses ||= [] @subclasses << subclass end |
.method_for_action(action) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/resource_kitling.rb', line 83 def self.method_for_action(action) Proc.new do |*args| client = args.shift pathopts = action.path.include?(':') ? args.shift : {} payload = args.shift payload = payload.to_h if payload.respond_to?(:to_h) client.call!( action.verb, action.generated_path(pathopts), payload, *args ) end end |
Instance Method Details
#actions ⇒ Object
95 96 97 |
# File 'lib/resource_kitling.rb', line 95 def actions self.class.actions end |