Class: Aequitas::VirtusIntegration::InlineAttributeRuleExtractor::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb

Direct Known Subclasses

Array, Boolean, Numeric, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ Object

Returns a new instance of Object.



12
13
14
# File 'lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb', line 12

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



10
11
12
# File 'lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb', line 10

def attribute
  @attribute
end

Instance Method Details

#extractObject



20
21
22
23
24
# File 'lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb', line 20

def extract
  inline_rules = []
  inline_rules.concat Array(extract_presence_rule)
  # inline_rules.concat Array(extract_primitive_type_rule)
end

#extract_presence_ruleObject



26
27
28
29
# File 'lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb', line 26

def extract_presence_rule
  required = options.fetch(:required, false)
  Rule::Presence::NotBlank.new(attribute.name) if required
end

#extract_primitive_type_ruleObject



31
32
33
# File 'lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb', line 31

def extract_primitive_type_rule
  Rule::PrimitiveType::Virtus.new(attribute.name, :attribute => attribute)
end

#optionsObject



16
17
18
# File 'lib/aequitas/virtus_integration/inline_attribute_rule_extractor/object.rb', line 16

def options
  attribute.options
end