Class: Statinize::Attribute
- Inherits:
-
Object
- Object
- 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
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add_options(opts) ⇒ Object
- #create ⇒ Object
-
#initialize(klass, name, opts) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(klass, name, opts) ⇒ Attribute
Returns a new instance of Attribute.
8 9 10 11 12 13 |
# File 'lib/statinize/attribute.rb', line 8 def initialize(klass, name, opts) @klass = klass @name = name @options = OptionsCollection.new @options << opts.clone.extend(Options) unless opts.empty? end |
Instance Attribute Details
#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 |
Class Method Details
.create(klass, name, opts = {}) ⇒ Object
15 16 17 |
# File 'lib/statinize/attribute.rb', line 15 def self.create(klass, name, opts = {}) new(klass, name, opts).create end |
Instance Method Details
#<=>(other) ⇒ Object
39 40 41 42 43 |
# File 'lib/statinize/attribute.rb', line 39 def <=>(other) name == other.name && == other. && klass == other.klass end |
#add_options(opts) ⇒ Object
35 36 37 |
# File 'lib/statinize/attribute.rb', line 35 def (opts) << opts.extend(Options) end |
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/statinize/attribute.rb', line 19 def create statinizer.add_attribute(self) unless 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 |