Class: Ricordami::Attribute
- Inherits:
-
Object
- Object
- Ricordami::Attribute
- Defined in:
- lib/ricordami/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #converter ⇒ Object
- #indexed ⇒ Object
- #indexed? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #read_only? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ricordami/attribute.rb', line 7 def initialize(name, = {}) .assert_valid_keys(:default, :read_only, :initial, :indexed, :type) if [:indexed] && ![:value, :unique].include?([:indexed]) raise InvalidIndexDefinition.new([:indexed].to_s) end [:type] ||= :string @options = @name = name.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/ricordami/attribute.rb', line 5 def name @name end |
Instance Method Details
#converter ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/ricordami/attribute.rb', line 44 def converter case @options[:type] when :string then :to_s when :integer then :to_i when :float then :to_f end end |
#indexed ⇒ Object
32 33 34 |
# File 'lib/ricordami/attribute.rb', line 32 def indexed @options[:indexed] end |
#indexed? ⇒ Boolean
36 37 38 |
# File 'lib/ricordami/attribute.rb', line 36 def indexed? !!@options[:indexed] end |
#read_only? ⇒ Boolean
28 29 30 |
# File 'lib/ricordami/attribute.rb', line 28 def read_only? !!@options[:read_only] end |
#type ⇒ Object
40 41 42 |
# File 'lib/ricordami/attribute.rb', line 40 def type @options[:type] end |