Class: Damsel::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/damsel/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/damsel/attribute.rb', line 5

def initialize(name, options={})
  o = {
      child: false,
      default: nil,
      type: String,
      klass: nil,
      many: false,
      named: false,
      block: nil,
  }.merge(options)
  @name = name.to_sym
  @child = o[:child]
  @default = o[:default]
  @named = o[:named]
  @many = o[:many]
  @klass = o[:klass]
  @type = o[:type]
  @block = o[:block]

  if type == Array
    @default = []
  elsif type == :child
    if many?
      @default = []
    else
      @default = {}
    end
  end
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/damsel/attribute.rb', line 3

def block
  @block
end

#defaultObject (readonly)

Returns the value of attribute default.



3
4
5
# File 'lib/damsel/attribute.rb', line 3

def default
  @default
end

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/damsel/attribute.rb', line 3

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/damsel/attribute.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/damsel/attribute.rb', line 3

def type
  @type
end

Instance Method Details

#child?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/damsel/attribute.rb', line 35

def child?
  @child
end

#many?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/damsel/attribute.rb', line 39

def many?
  @many
end

#named?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/damsel/attribute.rb', line 43

def named?
  @named
end