Class: RestModel::Key
- Inherits:
-
Object
- Object
- RestModel::Key
- Defined in:
- lib/rest_model/key.rb,
lib/rest_model/key/builder.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Builder
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#summarize ⇒ Object
Returns the value of attribute summarize.
Instance Method Summary collapse
- #convert_input_keys ⇒ Object
-
#initialize(name, options = {}) ⇒ Key
constructor
A new instance of Key.
- #present?(resource) ⇒ Boolean
- #relation? ⇒ Boolean
- #root_path? ⇒ Boolean
- #source_path ⇒ Object
- #visible?(resource) ⇒ Boolean
Constructor Details
#initialize(name, options = {}) ⇒ Key
Returns a new instance of Key.
5 6 7 8 |
# File 'lib/rest_model/key.rb', line 5 def initialize(name, = {}) @name = name = end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/rest_model/key.rb', line 3 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rest_model/key.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/rest_model/key.rb', line 3 def end |
#summarize ⇒ Object
Returns the value of attribute summarize.
3 4 5 |
# File 'lib/rest_model/key.rb', line 3 def summarize @summarize end |
Instance Method Details
#convert_input_keys ⇒ Object
10 11 12 13 |
# File 'lib/rest_model/key.rb', line 10 def convert_input_keys .fetch(:convert_input_keys, model.try(:convert_input_keys) || RestModel::Configuration.convert_input_keys) end |
#present?(resource) ⇒ Boolean
32 33 34 |
# File 'lib/rest_model/key.rb', line 32 def present?(resource) ![:if] ? true : resource.instance_eval(&[:if]) end |
#root_path? ⇒ Boolean
27 28 29 30 |
# File 'lib/rest_model/key.rb', line 27 def root_path? path_definition = .slice(:start_key, :field) path_definition.any? and path_definition.first[1].empty? end |
#source_path ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rest_model/key.rb', line 15 def source_path return @source_path.clone if @source_path @source_path = Source::Path.resolve(, convert_input_keys) if @source_path.empty? and !root_path? @source_path = convert_input_keys.call([name]) end @source_path.clone end |
#visible?(resource) ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'lib/rest_model/key.rb', line 36 def visible?(resource) !present?(resource) ? false : case visible = [:visible] when nil then true when Proc then resource.instance_eval(&visible) else visible end end |