Module: Superstore::AttributeMethods

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods
Included in:
Base
Defined in:
lib/superstore.rb,
lib/superstore/attribute_methods.rb,
lib/superstore/attribute_methods/dirty.rb,
lib/superstore/attribute_methods/definition.rb,
lib/superstore/attribute_methods/primary_key.rb,
lib/superstore/attribute_methods/typecasting.rb

Defined Under Namespace

Modules: ClassMethods, Dirty, PrimaryKey, Typecasting Classes: Definition

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object



64
65
66
67
68
69
# File 'lib/superstore/attribute_methods.rb', line 64

def method_missing(method_id, *args, &block)
  self.class.define_attribute_methods unless self.class.attribute_methods_generated?

  match = match_attribute_method?(method_id.to_s)
  match ? attribute_missing(match, *args, &block) : super
end

Instance Method Details

#attribute_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/superstore/attribute_methods.rb', line 46

def attribute_exists?(name)
  @attributes.key?(name.to_s)
end

#attributesObject



50
51
52
53
54
55
56
# File 'lib/superstore/attribute_methods.rb', line 50

def attributes
  results = {}
  @attributes.each_key do |key|
    results[key] = read_attribute(key)
  end
  results
end

#attributes=(attributes) ⇒ Object



58
59
60
61
62
# File 'lib/superstore/attribute_methods.rb', line 58

def attributes=(attributes)
  attributes.each do |(name, value)|
    send("#{name}=", value)
  end
end

#read_attribute(name) ⇒ Object



42
43
44
# File 'lib/superstore/attribute_methods.rb', line 42

def read_attribute(name)
  @attributes[name.to_s]
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/superstore/attribute_methods.rb', line 71

def respond_to?(*args)
  self.class.define_attribute_methods unless self.class.attribute_methods_generated?
  super
end

#write_attribute(name, value) ⇒ Object



38
39
40
# File 'lib/superstore/attribute_methods.rb', line 38

def write_attribute(name, value)
  @attributes[name.to_s] = self.class.typecast_attribute(name, value)
end