Class: Betterdocs::Dsl::Representer
- Inherits:
-
Object
- Object
- Betterdocs::Dsl::Representer
- Defined in:
- lib/betterdocs/dsl/representer.rb
Direct Known Subclasses
JsonParams::Param, Betterdocs::Dsl::Result::Link, Betterdocs::Dsl::Result::Property
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#representer ⇒ Object
readonly
Returns the value of attribute representer.
Instance Method Summary collapse
- #add_to_collector(collector) ⇒ Object
- #assign(result, object) ⇒ Object
- #assign?(object) ⇒ Boolean
-
#initialize(representer, name, options, &block) ⇒ Representer
constructor
A new instance of Representer.
Constructor Details
#initialize(representer, name, options, &block) ⇒ Representer
Returns a new instance of Representer.
2 3 4 5 6 7 8 9 10 |
# File 'lib/betterdocs/dsl/representer.rb', line 2 def initialize(representer, name, , &block) set_context @representer = representer @name = name.to_sym @options = | { if: -> { true }, unless: -> { false }, } block and instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/betterdocs/dsl/representer.rb', line 12 def name @name end |
#representer ⇒ Object (readonly)
Returns the value of attribute representer.
14 15 16 |
# File 'lib/betterdocs/dsl/representer.rb', line 14 def representer @representer end |
Instance Method Details
#add_to_collector(collector) ⇒ Object
25 26 27 |
# File 'lib/betterdocs/dsl/representer.rb', line 25 def add_to_collector(collector) raise NotImplementedError, 'add_to_collector needs to be implemented in subclass' end |
#assign(result, object) ⇒ Object
21 22 23 |
# File 'lib/betterdocs/dsl/representer.rb', line 21 def assign(result, object) raise NotImplementedError, 'assign needs to be implemented in subclass' end |
#assign?(object) ⇒ Boolean
16 17 18 19 |
# File 'lib/betterdocs/dsl/representer.rb', line 16 def assign?(object) object.instance_exec(&@options[:if]) && !object.instance_exec(&@options[:unless]) end |