Class: C::Node::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/cast/node.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default) ⇒ Field

Returns a new instance of Field.



702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/cast/node.rb', line 702

def initialize(name, default)
  name = name.to_s

  @child  = false
  @reader = name.to_sym
  @default = default

  if name[-1] == ?? then name[-1] = '' end
  @init_key = name.to_sym
  @var      = "@#{name}".to_sym
  @writer   = "#{name}=".to_sym
end

Instance Attribute Details

#child=(value) ⇒ Object (writeonly)

True if this field is a child field, false otherwise.



684
685
686
# File 'lib/cast/node.rb', line 684

def child=(value)
  @child = value
end

#defaultObject

Returns the value of attribute default.



678
679
680
# File 'lib/cast/node.rb', line 678

def default
  @default
end

#indexObject

Returns the value of attribute index.



678
679
680
# File 'lib/cast/node.rb', line 678

def index
  @index
end

#init_keyObject

Returns the value of attribute init_key.



678
679
680
# File 'lib/cast/node.rb', line 678

def init_key
  @init_key
end

#readerObject

Returns the value of attribute reader.



678
679
680
# File 'lib/cast/node.rb', line 678

def reader
  @reader
end

#varObject

Returns the value of attribute var.



678
679
680
# File 'lib/cast/node.rb', line 678

def var
  @var
end

#writerObject

Returns the value of attribute writer.



678
679
680
# File 'lib/cast/node.rb', line 678

def writer
  @writer
end

Instance Method Details

#child?Boolean

Returns:

  • (Boolean)


685
686
687
# File 'lib/cast/node.rb', line 685

def child?
  @child
end

#make_defaultObject

Create a default value for this field. This differs from #default in that if it's a Proc, it is called and the result returned.



694
695
696
697
698
699
700
# File 'lib/cast/node.rb', line 694

def make_default
  if @default.respond_to? :call
    @default.call
  else
    @default
  end
end