Class: Skroutz::Resource
- Inherits:
-
Object
- Object
- Skroutz::Resource
- Includes:
- Associations
- Defined in:
- lib/skroutz/resource.rb
Direct Known Subclasses
Address, Autocomplete, Category, Favorite, FavoriteList, FilterGroup, Location, Manufacturer, Notification, Product, Review, Shop, Sku, Specification
Instance Attribute Summary collapse
-
#attributes ⇒ Object
(also: #to_hash)
Returns the value of attribute attributes.
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(attributes, client) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
- #resource ⇒ Object
- #resource_prefix ⇒ Object
Methods included from UrlHelpers
Constructor Details
#initialize(attributes, client) ⇒ Resource
Returns a new instance of Resource.
8 9 10 11 |
# File 'lib/skroutz/resource.rb', line 8 def initialize(attributes, client) @attributes = attributes @client = client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object (protected)
rubocop: disable all
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/skroutz/resource.rb', line 44 def method_missing(method_symbol, *arguments) # rubocop: disable all method_name = method_symbol.to_s if method_name =~ /(=|\?)$/ case $1 when '=' attributes[$`] = arguments.first when '?' !!attributes[$`] end elsif attributes.include?(method_name) return attributes[method_name] else super end end |
Instance Attribute Details
#attributes ⇒ Object Also known as: to_hash
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/skroutz/resource.rb', line 4 def attributes @attributes end |
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/skroutz/resource.rb', line 4 def client @client end |
Instance Method Details
#inspect ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/skroutz/resource.rb', line 21 def inspect if attributes.present? inspection = attributes.map { |k, v| "#{k}: #{attribute_for_inspect(v)}" }.join(', ') else inspection = 'not initialized' end "#<#{self.class} #{inspection}>" end |
#resource ⇒ Object
13 14 15 |
# File 'lib/skroutz/resource.rb', line 13 def resource @resource ||= self.class.to_s.demodulize.tableize.singularize end |
#resource_prefix ⇒ Object
17 18 19 |
# File 'lib/skroutz/resource.rb', line 17 def resource_prefix @resource_prefix ||= resource.pluralize end |