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
-
#arg_name ⇒ Object
readonly
Returns the value of attribute arg_name.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#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 |
# File 'lib/statinize/attribute.rb', line 8 def initialize(klass, name, ) @klass = klass @name = name = = OptionsCollection.new # TODO: think of a better way << .clone.extend(Options) unless .empty? @default = [:default] if .key?(:default) @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 |
#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 end |
#options_collection ⇒ Object
Returns the value of attribute options_collection.
6 7 8 |
# File 'lib/statinize/attribute.rb', line 6 def end |
Class Method Details
.create(klass, name, options = {}) ⇒ Object
20 21 22 |
# File 'lib/statinize/attribute.rb', line 20 def self.create(klass, name, = {}) new(klass, name, ).create end |
Instance Method Details
#<=>(other) ⇒ Object
45 46 47 48 49 |
# File 'lib/statinize/attribute.rb', line 45 def <=>(other) name == other.name && == other. && klass == other.klass end |
#add_options(opts) ⇒ Object
41 42 43 |
# File 'lib/statinize/attribute.rb', line 41 def (opts) << opts.extend(Options) end |
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/statinize/attribute.rb', line 24 def create attribute? ? override : add_attribute klass.class_eval " def \#{name}\n @\#{name}\n end\n\n def \#{name}=(attr)\n @\#{name} = attr\n validate if respond_to?(:validate)\n attr\n end\n RUBY_EVAL\n self\nend\n", __FILE__, __LINE__ + 1 |