Class: QueryInterface::Client::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/query-interface-client/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Property

Returns a new instance of Property.



8
9
10
11
12
13
14
15
16
17
# File 'lib/query-interface-client/model.rb', line 8

def initialize(name, type, options={})
  unless conversion = QueryInterface::Client.types[type]
    raise "Unknown Type #{type}"
  end
  self.type = conversion
  self.primary = options.delete(:primary) { false }
  self.update = options.delete(:update) { true }
  self.array = options.delete(:array) { false }
  self.default = options.delete(:default) { lambda { nil } }
end

Instance Attribute Details

#arrayObject

Returns the value of attribute array.



6
7
8
# File 'lib/query-interface-client/model.rb', line 6

def array
  @array
end

#defaultObject

Returns the value of attribute default.



6
7
8
# File 'lib/query-interface-client/model.rb', line 6

def default
  @default
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/query-interface-client/model.rb', line 6

def name
  @name
end

#primaryObject

Returns the value of attribute primary.



6
7
8
# File 'lib/query-interface-client/model.rb', line 6

def primary
  @primary
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/query-interface-client/model.rb', line 6

def type
  @type
end

#updateObject

Returns the value of attribute update.



6
7
8
# File 'lib/query-interface-client/model.rb', line 6

def update
  @update
end

Instance Method Details

#run_get_conversion(value) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/query-interface-client/model.rb', line 19

def run_get_conversion(value)
  if self.array
    value ||= []
    value.map { |item| self.type.apply_get(item) }
  else
    self.type.apply_get(value) unless value.nil?
  end
end

#run_set_conversion(value) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/query-interface-client/model.rb', line 28

def run_set_conversion(value)
  if self.array
    value ||= []
    value.map { |item| self.type.apply_set(item) }
  else
    self.type.apply_set(value) unless value.nil?
  end
end