Class: Filemaker::Model::Field
- Inherits:
-
Object
- Object
- Filemaker::Model::Field
- Defined in:
- lib/filemaker/model/field.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#fm_name ⇒ Object
readonly
Returns the value of attribute fm_name.
-
#max_repeat ⇒ Object
readonly
Returns the value of attribute max_repeat.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#cast(value) ⇒ Object
Will delegate to the underlying @type for casting From raw input to Ruby type.
-
#initialize(name, type, options = {}) ⇒ Field
constructor
A new instance of Field.
-
#serialize_for_query(value) ⇒ Object
Convert to Ruby type situable for making FileMaker query.
-
#serialize_for_update(value) ⇒ Object
Convert to Ruby type situable for making FileMaker update For attr_writer.
Constructor Details
#initialize(name, type, options = {}) ⇒ Field
Returns a new instance of Field.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/filemaker/model/field.rb', line 6 def initialize(name, type, = {}) @name = name @type = type @max_repeat = .fetch(:max_repeat) { 1 } @default_value = serialize_for_update(.fetch(:default) { nil }) # We need to downcase because Filemaker::Record is # HashWithIndifferentAndCaseInsensitiveAccess @fm_name = (.fetch(:fm_name) { name }).to_s.downcase.freeze end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
4 5 6 |
# File 'lib/filemaker/model/field.rb', line 4 def default_value @default_value end |
#fm_name ⇒ Object (readonly)
Returns the value of attribute fm_name.
4 5 6 |
# File 'lib/filemaker/model/field.rb', line 4 def fm_name @fm_name end |
#max_repeat ⇒ Object (readonly)
Returns the value of attribute max_repeat.
4 5 6 |
# File 'lib/filemaker/model/field.rb', line 4 def max_repeat @max_repeat end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/filemaker/model/field.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/filemaker/model/field.rb', line 4 def type @type end |
Instance Method Details
#cast(value) ⇒ Object
Will delegate to the underlying @type for casting From raw input to Ruby type
19 20 21 22 23 24 25 26 27 |
# File 'lib/filemaker/model/field.rb', line 19 def cast(value) return value if value.nil? return value if value.is_a?(Array) && @max_repeat > 1 @type.__filemaker_cast_to_ruby_object(value) rescue StandardError => e warn "[#{e.}] Could not cast: #{name}=#{value}" value end |
#serialize_for_query(value) ⇒ Object
Convert to Ruby type situable for making FileMaker query
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/filemaker/model/field.rb', line 54 def serialize_for_query(value) return value if value.nil? return value if value =~ /^==|=\*/ return value if value =~ /(\.\.\.)/ return value if value =~ /\A(<|<=|>|>=)/ @type.__filemaker_serialize_for_query(value) rescue StandardError => e warn "[#{e.}] Could not serialize for query: #{name}=#{value}" value end |
#serialize_for_update(value) ⇒ Object
Convert to Ruby type situable for making FileMaker update For attr_writer
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/filemaker/model/field.rb', line 31 def serialize_for_update(value) return value if value.nil? if value.is_a?(Array) && @max_repeat > 1 value.map { |v| @type.__filemaker_serialize_for_update(v) } # @max_repeat.times do |idx| # index = idx + 1 # repeated_field_name = "@#{@name}__#{index}" # repeated_field_value = @type.__filemaker_serialize_for_update(value[idx]) # instance_eval do # instance_variable_set(repeated_field_name, repeated_field_value) # end # end else @type.__filemaker_serialize_for_update(value) end rescue StandardError => e warn "[#{e.}] Could not serialize for update: #{name}=#{value}" value end |