Class: Responsible::Base
- Inherits:
-
Object
- Object
- Responsible::Base
- Defined in:
- lib/responsible.rb
Instance Attribute Summary collapse
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(opt = {}) ⇒ Object
-
#initialize(consumer, data) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(consumer, data) ⇒ Base
Returns a new instance of Base.
38 39 40 41 42 43 44 45 46 |
# File 'lib/responsible.rb', line 38 def initialize(consumer, data) @consumer, @data = consumer, data undefined_properties = _properties_.keys - methods if undefined_properties.any? raise Responsible::PropertyNotImplemented, undefined_properties.join(", ") end end |
Instance Attribute Details
#consumer ⇒ Object (readonly)
Returns the value of attribute consumer.
36 37 38 |
# File 'lib/responsible.rb', line 36 def consumer @consumer end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
36 37 38 |
# File 'lib/responsible.rb', line 36 def data @data end |
Class Method Details
.doc(str = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/responsible.rb', line 9 def doc(str=nil) @doc ||= [] @doc << str if str @doc end |
.properties ⇒ Object
23 24 25 |
# File 'lib/responsible.rb', line 23 def properties @properties ||= {} end |
.property(name, options = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/responsible.rb', line 15 def property(name, ={}) unknown_configuration_params = .keys - [:delegate, :to, :restrict_to, :doc] raise(Responsible::UnknownConfigurationParameter, unknown_configuration_params.join(", ")) if unknown_configuration_params.any? properties[name.to_sym] = delegate_method(name, [:to]) if [:delegate] end |
Instance Method Details
#as_json(opt = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/responsible.rb', line 48 def as_json(opt={}) result = {} _properties_.each do |name, | if consumer.can_see?([:restrict_to]) result[name] = send(name) end end result end |