Class: Servitium::ScopedAttributes
- Inherits:
-
Object
- Object
- Servitium::ScopedAttributes
- Defined in:
- lib/servitium/scoped_attributes.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#validation_context ⇒ Object
readonly
Returns the value of attribute validation_context.
Instance Method Summary collapse
- #attribute(name) ⇒ Object
- #call(block) ⇒ Object
-
#initialize(context, store, validation_context = nil) ⇒ ScopedAttributes
constructor
A new instance of ScopedAttributes.
- #validate(name, options = {}) ⇒ Object
- #validates(name, options = {}) ⇒ Object
Constructor Details
#initialize(context, store, validation_context = nil) ⇒ ScopedAttributes
Returns a new instance of ScopedAttributes.
7 8 9 10 11 |
# File 'lib/servitium/scoped_attributes.rb', line 7 def initialize(context, store, validation_context = nil) @context = context @store = store @validation_context = validation_context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/servitium/scoped_attributes.rb', line 5 def context @context end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
5 6 7 |
# File 'lib/servitium/scoped_attributes.rb', line 5 def store @store end |
#validation_context ⇒ Object (readonly)
Returns the value of attribute validation_context.
5 6 7 |
# File 'lib/servitium/scoped_attributes.rb', line 5 def validation_context @validation_context end |
Instance Method Details
#attribute(name) ⇒ Object
13 14 15 16 |
# File 'lib/servitium/scoped_attributes.rb', line 13 def attribute(name, *) store << name.to_s context.send(:attribute, name, *) end |
#call(block) ⇒ Object
28 29 30 |
# File 'lib/servitium/scoped_attributes.rb', line 28 def call(block) instance_exec(&block) end |
#validate(name, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/servitium/scoped_attributes.rb', line 23 def validate(name, = {}, &) [:on] ||= validation_context if validation_context context.send(:validate, name, , &) end |
#validates(name, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/servitium/scoped_attributes.rb', line 18 def validates(name, = {}) [:on] ||= validation_context if validation_context context.send(:validates, name, ) end |