Class: HecksDomainBuilder::Attribute
- Inherits:
-
Object
- Object
- HecksDomainBuilder::Attribute
- Defined in:
- lib/domain_builder/attribute.rb
Overview
A Domain Object attribute
Instance Attribute Summary collapse
-
#object_name ⇒ Object
readonly
Returns the value of attribute object_name.
- #type ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #copy(new_values = {}) ⇒ Object
- #domain_module ⇒ Object
- #domain_reference? ⇒ Boolean
-
#initialize(string) ⇒ Attribute
constructor
A new instance of Attribute.
- #list? ⇒ Boolean
- #name ⇒ Object
- #primitive? ⇒ Boolean
- #reference? ⇒ Boolean
- #referenced_object ⇒ Object
Constructor Details
#initialize(string) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 |
# File 'lib/domain_builder/attribute.rb', line 7 def initialize(string) @string = string @object_name = object_name end |
Instance Attribute Details
#object_name ⇒ Object (readonly)
Returns the value of attribute object_name.
5 6 7 |
# File 'lib/domain_builder/attribute.rb', line 5 def object_name @object_name end |
#type ⇒ Object
20 21 22 23 |
# File 'lib/domain_builder/attribute.rb', line 20 def type return @type if @type @string.split(":").last.delete("[").delete("]").camelize end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/domain_builder/attribute.rb', line 54 def ==(other) return false if other.name != name return false if other.type != type return false if other.domain_module != domain_module return true end |
#copy(new_values = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/domain_builder/attribute.rb', line 30 def copy(new_values={}) result = self.class.new(@string) result.type = new_values[:type] if new_values[:type] result end |
#domain_module ⇒ Object
25 26 27 28 |
# File 'lib/domain_builder/attribute.rb', line 25 def domain_module return unless @string.include?("::") @string.split("::").first.split(":").last.camelize end |
#domain_reference? ⇒ Boolean
40 41 42 |
# File 'lib/domain_builder/attribute.rb', line 40 def domain_reference? @string.include?('::') end |
#list? ⇒ Boolean
12 13 14 |
# File 'lib/domain_builder/attribute.rb', line 12 def list? @string.include?("[") end |
#name ⇒ Object
16 17 18 |
# File 'lib/domain_builder/attribute.rb', line 16 def name @string.split(":").first end |
#primitive? ⇒ Boolean
50 51 52 |
# File 'lib/domain_builder/attribute.rb', line 50 def primitive? ['String', 'Integer', 'Currency'].include?(type) end |
#reference? ⇒ Boolean
36 37 38 |
# File 'lib/domain_builder/attribute.rb', line 36 def reference? !primitive? && !list? end |
#referenced_object ⇒ Object
44 45 46 47 48 |
# File 'lib/domain_builder/attribute.rb', line 44 def referenced_object return unless reference? return @string.split("::").last if @string.include?("::") @string.split(":").last end |