Class: Smooth::MetaData::Inspector
- Inherits:
-
Object
- Object
- Smooth::MetaData::Inspector
- Defined in:
- lib/smooth/meta_data/inspector.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(resource) ⇒ Inspector
constructor
A new instance of Inspector.
- #presentable_settings ⇒ Object
- #presenters ⇒ Object
- #queryable_parameters ⇒ Object
- #queryable_settings ⇒ Object
- #resource_is_presentable? ⇒ Boolean
- #resource_is_queryable? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(resource) ⇒ Inspector
Returns a new instance of Inspector.
6 7 8 9 |
# File 'lib/smooth/meta_data/inspector.rb', line 6 def initialize(resource) @resource = resource @resource = resource.to_s.camelize.constantize if resource.is_a?(String) or resource.is_a?(Symbol) end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
4 5 6 |
# File 'lib/smooth/meta_data/inspector.rb', line 4 def resource @resource end |
Instance Method Details
#as_json ⇒ Object
62 63 64 |
# File 'lib/smooth/meta_data/inspector.rb', line 62 def as_json to_hash end |
#presentable_settings ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/smooth/meta_data/inspector.rb', line 33 def presentable_settings return {} unless resource_is_presentable? { presentable: { formats: presenters } } end |
#presenters ⇒ Object
11 12 13 14 15 16 |
# File 'lib/smooth/meta_data/inspector.rb', line 11 def presenters methods = [:default] methods += resource.presenter_class.public_methods - Object.methods methods.uniq end |
#queryable_parameters ⇒ Object
18 19 20 |
# File 'lib/smooth/meta_data/inspector.rb', line 18 def queryable_parameters resource.queryable_keys end |
#queryable_settings ⇒ Object
22 23 |
# File 'lib/smooth/meta_data/inspector.rb', line 22 def queryable_settings end |
#resource_is_presentable? ⇒ Boolean
25 26 27 |
# File 'lib/smooth/meta_data/inspector.rb', line 25 def resource_is_presentable? resource && resource.ancestors.include?(Smooth::Presentable) end |
#resource_is_queryable? ⇒ Boolean
29 30 31 |
# File 'lib/smooth/meta_data/inspector.rb', line 29 def resource_is_queryable? resource && resource.ancestors.include?(Smooth::Queryable) end |
#to_hash ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/smooth/meta_data/inspector.rb', line 54 def to_hash hash = {} hash.merge!(presentable_settings) hash.merge!(queryable_settings) hash end |