Class: Tinybucket::Model::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, Concerns::AcceptableAttributes, Concerns::ApiCallable, Concerns::Enumerable, Concerns::Reloadable
Defined in:
lib/tinybucket/model/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Base

Returns a new instance of Base.



17
18
19
20
# File 'lib/tinybucket/model/base.rb', line 17

def initialize(json)
  self.attributes = json
  @_loaded = !json.empty?
end

Class Method Details

.concern_included?(concern_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/tinybucket/model/base.rb', line 12

def self.concern_included?(concern_name)
  mod_name = "Tinybucket::Model::Concerns::#{concern_name}".constantize
  ancestors.include?(mod_name)
end

Instance Method Details

#attributesObject



32
33
34
35
36
# File 'lib/tinybucket/model/base.rb', line 32

def attributes
  acceptable_attributes.map do |key|
    { key => send(key.intern) }
  end.reduce(&:merge)
end

#attributes=(hash) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/tinybucket/model/base.rb', line 22

def attributes=(hash)
  hash.each_pair do |key, value|
    if acceptable_attribute?(key)
      send("#{key}=".intern, value)
    else
      logger.warn("Ignored '#{key}' attribute (value: #{value}). [#{self.class}]")
    end
  end
end