Class: Fauxsql::AttributeWrapper

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Concern
Defined in:
lib/fauxsql/attribute_wrapper.rb

Direct Known Subclasses

ListWrapper, ManymanyWrapper, MapWrapper

Defined Under Namespace

Classes: MissingOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, record, name, options) ⇒ AttributeWrapper

Returns a new instance of AttributeWrapper.

Raises:



14
15
16
17
18
# File 'lib/fauxsql/attribute_wrapper.rb', line 14

def initialize(attribute, record, name, options)
  raise MissingOptions if options.nil?
  @attribute, @record, @name, @options = attribute, record, name, options
  @record.fauxsql_attributes[name] ||= attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



9
10
11
# File 'lib/fauxsql/attribute_wrapper.rb', line 9

def attribute
  @attribute
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/fauxsql/attribute_wrapper.rb', line 11

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/fauxsql/attribute_wrapper.rb', line 12

def options
  @options
end

#recordObject (readonly)

Returns the value of attribute record.



10
11
12
# File 'lib/fauxsql/attribute_wrapper.rb', line 10

def record
  @record
end

Instance Method Details

#dirty!Object



27
28
29
# File 'lib/fauxsql/attribute_wrapper.rb', line 27

def dirty!
  Fauxsql.dirty!(record){ yield }
end

#get_nested_record(vals) ⇒ Object

Raises:



20
21
22
23
24
25
# File 'lib/fauxsql/attribute_wrapper.rb', line 20

def get_nested_record(vals)
  model = vals[:type].constantize
  raise MissingOptions.new(:nest, options) unless options[:nest]
  raise InvalidNesting unless options[:nest].include?(model)
  model.get(vals["#{model.name}_id".to_sym])
end