Module: Statinize::DSL
- Included in:
- Statinizer
- Defined in:
- lib/statinize/dsl.rb
Instance Method Summary collapse
- #attribute(*attrs, **options) ⇒ Object
- #before(&block) ⇒ Object
- #force(force = nil) ⇒ Object
- #validate(*attrs, **options) ⇒ Object
- #with(**options, &block) ⇒ Object
Instance Method Details
#attribute(*attrs, **options) ⇒ Object
4 5 6 7 8 |
# File 'lib/statinize/dsl.rb', line 4 def attribute(*attrs, **) attrs.each do |attr| Attribute.create(klass, attr, ) unless attribute? attr end end |
#before(&block) ⇒ Object
31 32 33 34 35 |
# File 'lib/statinize/dsl.rb', line 31 def before(&block) return unless block_given? before_callbacks << block end |
#force(force = nil) ⇒ Object
37 38 39 |
# File 'lib/statinize/dsl.rb', line 37 def force(force = nil) force.nil? ? @force : @force = force end |
#validate(*attrs, **options) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/statinize/dsl.rb', line 10 def validate(*attrs, **) attrs.each do |attr| attribute = attributes.find { _1.name == attr } attribute = Attribute.create(klass, attr) unless attribute attribute.() end end |
#with(**options, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/statinize/dsl.rb', line 18 def with(**, &block) instance = self.class.new(klass) instance.force(force) klass.instance_variable_set(:@statinizer, instance) instance.instance_exec(&block) klass.instance_variable_set(:@statinizer, self) instance.(**) populate(instance.attributes) end |