Class: Rumx::Type
- Inherits:
-
Object
- Object
- Rumx::Type
- Defined in:
- lib/rumx/type.rb
Constant Summary collapse
- @@allowed_types =
{ :integer => new(:integer, Attribute, lambda {|s| s.to_i}), :float => new(:float, Attribute, lambda {|s| s.to_f}), :string => new(:string, Attribute, lambda {|s| s.to_s}), :symbol => new(:symbol, Attribute, lambda {|s| s.to_sym}), :boolean => new(:boolean, Attribute, lambda {|s| s.to_s == 'true'}), :list => new(:list, ListAttribute, nil), :hash => new(:hash, HashAttribute, nil), :void => new(:void, nil, lambda {|s| nil}, lambda {|v| ''}) }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #create_attribute(name, description, allow_read, allow_write, options) ⇒ Object
-
#initialize(name, attribute_class, string_to_value_proc, value_to_string_proc = lambda{|v| v.to_s}) ⇒ Type
constructor
A new instance of Type.
- #string_to_value(string) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, attribute_class, string_to_value_proc, value_to_string_proc = lambda{|v| v.to_s}) ⇒ Type
Returns a new instance of Type.
11 12 13 14 15 16 |
# File 'lib/rumx/type.rb', line 11 def initialize(name, attribute_class, string_to_value_proc, value_to_string_proc=lambda{|v| v.to_s}) @name = name @attribute_class = attribute_class @string_to_value_proc = string_to_value_proc @value_to_string_proc = value_to_string_proc end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/rumx/type.rb', line 3 def name @name end |
Class Method Details
.find(type_name) ⇒ Object
5 6 7 8 9 |
# File 'lib/rumx/type.rb', line 5 def self.find(type_name) type = @@allowed_types[type_name.to_sym] raise "No such type=#{type_name} in Rumx::Type" unless type type end |
Instance Method Details
#create_attribute(name, description, allow_read, allow_write, options) ⇒ Object
18 19 20 |
# File 'lib/rumx/type.rb', line 18 def create_attribute(name, description, allow_read, allow_write, ) @attribute_class.new(name, self, description, allow_read, allow_write, ) end |
#string_to_value(string) ⇒ Object
22 23 24 |
# File 'lib/rumx/type.rb', line 22 def string_to_value(string) @string_to_value_proc.call(string) end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/rumx/type.rb', line 26 def to_s @name.to_s end |