Class: Modeling::ModelField
- Inherits:
-
Object
- Object
- Modeling::ModelField
- Defined in:
- lib/modeling/model_field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, instance_variable, writer, reader, tester) ⇒ ModelField
constructor
A new instance of ModelField.
- #instance_variable? ⇒ Boolean
- #instance_variable_name ⇒ Object
- #reader? ⇒ Boolean
- #tester? ⇒ Boolean
- #writer? ⇒ Boolean
Constructor Details
#initialize(name, instance_variable, writer, reader, tester) ⇒ ModelField
Returns a new instance of ModelField.
3 4 5 6 7 8 9 |
# File 'lib/modeling/model_field.rb', line 3 def initialize name, instance_variable, writer, reader, tester @name = name @instance_variable = instance_variable @writer = writer @reader = reader @tester = tester end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/modeling/model_field.rb', line 11 def name @name end |
Class Method Details
.parse(argument, filter = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/modeling/model_field.rb', line 34 def parse argument, filter = nil case argument when ModelField argument when Symbol, String parse_model_field argument else raise "Unsupported argument #{argument} of #{argument.class} class." end end |
.parse_model_field(argument) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/modeling/model_field.rb', line 45 def parse_model_field argument instance_variable = reader = writer = tester = false if argument.start_with? "@" , name = argument.to_s.split "_", 2 .to_s.each_char do |char| case char when "r", "R" then reader = true when "w", "W" then writer = true when "t", "T" then tester = true when "i", "I" then instance_variable = true end end else name = argument reader = writer = instance_variable = true end raise "Invalid model field #{argument}" unless name =~ /\w+/ ModelField.new name.to_sym, instance_variable, writer, reader, tester end |
Instance Method Details
#instance_variable? ⇒ Boolean
17 18 19 |
# File 'lib/modeling/model_field.rb', line 17 def instance_variable? @instance_variable end |
#instance_variable_name ⇒ Object
13 14 15 |
# File 'lib/modeling/model_field.rb', line 13 def instance_variable_name "@#{name}" end |
#reader? ⇒ Boolean
25 26 27 |
# File 'lib/modeling/model_field.rb', line 25 def reader? @reader end |
#tester? ⇒ Boolean
29 30 31 |
# File 'lib/modeling/model_field.rb', line 29 def tester? @tester end |
#writer? ⇒ Boolean
21 22 23 |
# File 'lib/modeling/model_field.rb', line 21 def writer? @writer end |