Class: Smooth::MetaData::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/smooth/meta_data/inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resourceObject

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_jsonObject



62
63
64
# File 'lib/smooth/meta_data/inspector.rb', line 62

def as_json
  to_hash
end

#presentable_settingsObject



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

#presentersObject



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_parametersObject



18
19
20
# File 'lib/smooth/meta_data/inspector.rb', line 18

def queryable_parameters
  resource.queryable_keys
end

#queryable_settingsObject



22
23
# File 'lib/smooth/meta_data/inspector.rb', line 22

def queryable_settings
end

#resource_is_presentable?Boolean

Returns:

  • (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

Returns:

  • (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_hashObject



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