Class: Servitium::ScopedAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/servitium/scoped_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/servitium/scoped_attributes.rb', line 5

def context
  @context
end

#storeObject (readonly)

Returns the value of attribute store.



5
6
7
# File 'lib/servitium/scoped_attributes.rb', line 5

def store
  @store
end

#validation_contextObject (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, options = {}, &)
  options[:on] ||= validation_context if validation_context
  context.send(:validate, name, options, &)
end

#validates(name, options = {}) ⇒ Object



18
19
20
21
# File 'lib/servitium/scoped_attributes.rb', line 18

def validates(name, options = {})
  options[:on] ||= validation_context if validation_context
  context.send(:validates, name, options)
end