Class: Statinize::Attribute
- Includes:
- Comparable
- Defined in:
- lib/statinize/attribute.rb,
lib/statinize/attribute/options.rb,
lib/statinize/attribute/options/conditions.rb,
lib/statinize/attribute/options_collection.rb
Defined Under Namespace
Modules: Options Classes: OptionsCollection
Instance Attribute Summary collapse
-
#arg_name ⇒ Object
readonly
Returns the value of attribute arg_name.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#default_exec ⇒ Object
readonly
Returns the value of attribute default_exec.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#options_collection ⇒ Object
Returns the value of attribute options_collection.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add_options(opts) ⇒ Object
- #create ⇒ Object
-
#initialize(klass, name, options) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(klass, name, options) ⇒ Attribute
Returns a new instance of Attribute.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/statinize/attribute.rb', line 8 def initialize(klass, name, ) @klass = klass @name = name @options = @options_collection = OptionsCollection.new # TODO: think of a better way @options_collection << .clone.extend(Options) unless .empty? @default = [:default] if .key?(:default) @default_exec = [:default_exec] if .key?(:default_exec) @arg_name = name @name = [:name] || name end |
Instance Attribute Details
#arg_name ⇒ Object (readonly)
Returns the value of attribute arg_name.
5 6 7 |
# File 'lib/statinize/attribute.rb', line 5 def arg_name @arg_name end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/statinize/attribute.rb', line 5 def default @default end |
#default_exec ⇒ Object (readonly)
Returns the value of attribute default_exec.
5 6 7 |
# File 'lib/statinize/attribute.rb', line 5 def default_exec @default_exec end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/statinize/attribute.rb', line 5 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/statinize/attribute.rb', line 5 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/statinize/attribute.rb', line 6 def @options end |
#options_collection ⇒ Object
Returns the value of attribute options_collection.
6 7 8 |
# File 'lib/statinize/attribute.rb', line 6 def @options_collection end |
Class Method Details
.create(klass, name, options = {}) ⇒ Object
21 22 23 |
# File 'lib/statinize/attribute.rb', line 21 def self.create(klass, name, = {}) new(klass, name, ).create end |
Instance Method Details
#<=>(other) ⇒ Object
46 47 48 49 50 |
# File 'lib/statinize/attribute.rb', line 46 def <=>(other) name == other.name && == other. && klass == other.klass end |
#add_options(opts) ⇒ Object
42 43 44 |
# File 'lib/statinize/attribute.rb', line 42 def (opts) << opts.extend(Options) end |
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/statinize/attribute.rb', line 25 def create attribute? ? override : add_attribute klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{name} @#{name} end def #{name}=(attr) @#{name} = attr validate if respond_to?(:validate) attr end RUBY_EVAL self end |