Module: Trax::Model::Attributes::Dsl::ClassMethods
- Defined in:
- lib/trax/model/attributes/dsl.rb
Instance Method Summary collapse
- #define_attributes(&block) ⇒ Object
- #evaluate_attribute_definitions_blocks ⇒ Object
- #fields ⇒ Object
- #fields_module ⇒ Object
- #trax_attribute(name, type:, **options, &block) ⇒ Object
Instance Method Details
#define_attributes(&block) ⇒ Object
12 13 14 |
# File 'lib/trax/model/attributes/dsl.rb', line 12 def define_attributes(&block) self.instance_variable_set("@_attribute_definitions_block", block) end |
#evaluate_attribute_definitions_blocks ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/trax/model/attributes/dsl.rb', line 38 def evaluate_attribute_definitions_blocks model_klass_proxy = ::Trax::Model::Attributes::Definitions.new(self) attribute_definition_blocks = self.superclasses_until(::ActiveRecord::Base, self, [ self ]).map{ |klass| klass.instance_variable_get(:@_attribute_definitions_block) }.compact attribute_definition_blocks.each do |blk| model_klass_proxy.instance_eval(&blk) end if attribute_definition_blocks.any? end |
#fields ⇒ Object
23 24 25 |
# File 'lib/trax/model/attributes/dsl.rb', line 23 def fields @fields ||= fields_module end |
#fields_module ⇒ Object
16 17 18 19 20 21 |
# File 'lib/trax/model/attributes/dsl.rb', line 16 def fields_module @fields_module ||= begin module_name = "#{self.name}::Fields" ::Trax::Core::NamedModule.new(module_name, ::Trax::Model::Attributes::Fields, :definition_context => self) end end |
#trax_attribute(name, type:, **options, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/trax/model/attributes/dsl.rb', line 27 def trax_attribute(name, type:, **, &block) raise ::Trax::Model::Attributes::Errors::UnknownAttributeType.new(type: type) unless ::Trax::Model::Attributes.key?(type) if ::Trax::Model::Attributes[type].respond_to?(:define_attribute) ::Trax::Model::Attributes[type].define_attribute(self, name, **, &block) self.validates(name, [:validates]) if .key?(:validates) else raise ::Trax::Model::Attributes::Errors::UnknownAttributeType.new(type: type) end end |