Class: Calculi::Attribute::Abstract Abstract

Inherits:
Module
  • Object
show all
Includes:
Utility
Defined in:
lib/calculi/attribute/abstract.rb

Overview

This class is abstract.

Typed attributes with defaults.

Direct Known Subclasses

Boolean, Duration, Integer, Procable, String

Constant Summary collapse

NO_DEFAULT =
Object.new
PASSTHRU =
->(o) { o }

Constants included from Utility

Utility::NON_IVAR, Utility::NULL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#at_prefixed, #callable?, #constantly, #eval_or_value, #instance_variable_compute, #procable?, #set_attribute

Constructor Details

#initialize(name, options = {}, &setter) ⇒ Abstract

Returns a new instance of Abstract.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/calculi/attribute/abstract.rb', line 36

def initialize(name, options = {}, &setter)
  @name       = name.to_s

  @ivar_name  = at_prefixed name

  @default    = options.fetch :default, NO_DEFAULT

  @readonly   = !!options.fetch(:readonly, false)

  @setter     = block_given? ? setter : options.fetch(:setter) { default_setter }

  define_attribute_methods!
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



9
10
11
# File 'lib/calculi/attribute/abstract.rb', line 9

def default
  @default
end

#ivar_nameObject (readonly)

Returns the value of attribute ivar_name.



14
15
16
# File 'lib/calculi/attribute/abstract.rb', line 14

def ivar_name
  @ivar_name
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/calculi/attribute/abstract.rb', line 19

def name
  @name
end

#setterObject (readonly)

Returns the value of attribute setter.



24
25
26
# File 'lib/calculi/attribute/abstract.rb', line 24

def setter
  @setter
end

Instance Method Details

#default?Boolean

Returns:



56
57
58
# File 'lib/calculi/attribute/abstract.rb', line 56

def default?
  default != NO_DEFAULT
end

#default_setterProc

This method is abstract.

Returns:

  • (Proc)


52
53
54
# File 'lib/calculi/attribute/abstract.rb', line 52

def default_setter
  PASSTHRU
end

#inspectObject



60
61
62
# File 'lib/calculi/attribute/abstract.rb', line 60

def inspect
  "#{self.class}(:name, :default => #{default.inspect})"
end

#readonly?Boolean

Returns:



64
65
66
# File 'lib/calculi/attribute/abstract.rb', line 64

def readonly?
  @readonly
end