Class: Doodle::DoodleAttribute

Inherits:
Doodle
  • Object
show all
Extended by:
ClassMethods
Defined in:
lib/doodle/attribute.rb

Overview

Attribute is itself a Doodle object that is created by #has and added to the #attributes collection in an object’s DoodleInfo

It is used to provide a context for defining #must and #from rules

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from ClassMethods

params_from_args

Methods inherited from Doodle

TypedArray, raise_exception_on_error, raise_exception_on_error=

Methods included from ClassMethods

#context, #parent

Methods included from JSON

included

Methods included from Core::ModuleMethods

#included

Instance Method Details

#abstractObject

temporarily fake existence of abstract attribute - later has :abstract overrides this



134
135
136
# File 'lib/doodle/attribute.rb', line 134

def abstract
  @abstract = false
end

#default_defined?Boolean

has default been defined?

Returns:

  • (Boolean)


109
110
111
# File 'lib/doodle/attribute.rb', line 109

def default_defined?
  ivar_defined?(:default)
end

#init_defined?Boolean

has default been defined?

Returns:

  • (Boolean)


114
115
116
# File 'lib/doodle/attribute.rb', line 114

def init_defined?
  ivar_defined?(:init)
end

#optional?Boolean

is this attribute optional? true if it has a default defined for it

Returns:

  • (Boolean)


119
120
121
# File 'lib/doodle/attribute.rb', line 119

def optional?
  default_defined? or init_defined?
end

#readonlyObject

temporarily fake existence of readonly attribute



139
140
141
# File 'lib/doodle/attribute.rb', line 139

def readonly
  false
end

#required?Boolean

an attribute is required if it has no default or initial value defined for it

Returns:

  • (Boolean)


124
125
126
127
# File 'lib/doodle/attribute.rb', line 124

def required?
  # d { [:default?, self.class, self.name, instance_variable_defined?("@default"), @default] }
  !optional?
end

#validate!(all = true) ⇒ Object

hack: bump off validate! for Attributes - maybe better way of doing this however, without this, tries to validate Attribute to :kind specified, e.g. if you have

has :date, :kind => Date

it will fail because Attribute is not a kind of Date - obviously, I have to think about this some more :S

at least, I could hand roll a custom validate! method for Attribute



105
106
# File 'lib/doodle/attribute.rb', line 105

def validate!(all = true)
end