Module: Oshpark::Model

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oshpark/model.rb', line 14

def self.included base
  base.send :extend, ClassMethods

  base.instance_eval do
    attr_reader *base.attrs
  end

  base.write_attrs.each do |attr|
    define_method "#{attr}=" do |new_value|
      @dirty_attributes << attr unless @dirty_attributes.include?(attr)
      instance_variable_set "@#{attr}".to_sym, new_value
    end
  end if base.respond_to? :write_attrs
end

Instance Method Details

#dirty?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/oshpark/model.rb', line 10

def dirty?
  @dirty_attributes.size > 0
end

#initialize(json) ⇒ Object



6
7
8
# File 'lib/oshpark/model.rb', line 6

def initialize json
  reload_with json
end