Class: ConfigureMe::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks, Loading
Includes:
ActiveModel::Conversion, AttributeMethods, Caching, Naming, Nesting, Persistence, Persisting, Validations
Defined in:
lib/configure_me/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loading

from_hash, load

Methods included from Validations

#save, #valid?

Methods included from Persisting

#persist_guard, #read_persist, #write_persist

Methods included from Persistence

#save, #update_attributes

Methods included from Caching

#read_cache, #write_cache

Methods included from AttributeMethods

#read_attribute, #write_attribute

Class Method Details

.config_keyObject



48
49
50
51
52
# File 'lib/configure_me/base.rb', line 48

def config_key
  key = parent_config_klass.nil? ? [] : parent_config_klass.config_key
  key << self.config_name
  key
end

.config_nameObject



54
55
56
# File 'lib/configure_me/base.rb', line 54

def config_name
  self.name.demodulize.gsub(/^(.*)Config$/, '\1').underscore
end

.find_by_id(id) ⇒ Object

def respond_to?(method_sym, include_private = false)

instance.children.each_pair do |name, instance|
  if name.to_s.eql?(method_sym.to_s)
    return true
  end
end
if class_settings.key?(method_sym)
  return true
end
super

end



78
79
80
81
82
83
84
85
# File 'lib/configure_me/base.rb', line 78

def find_by_id(id)
  configs.each do |config|
    if config.config_name.eql?(id)
      return config.new
    end
  end
  nil
end

.inherited(subclass) ⇒ Object



43
44
45
46
# File 'lib/configure_me/base.rb', line 43

def inherited(subclass)
  super
  configs << subclass
end

Instance Method Details

#persisted?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/configure_me/base.rb', line 17

def persisted?
  true
end

#storage_key(name) ⇒ Object



38
39
40
# File 'lib/configure_me/base.rb', line 38

def storage_key(name)
  "#{to_param}-#{name.to_s}"
end

#to_keyObject



21
22
23
24
25
26
27
28
# File 'lib/configure_me/base.rb', line 21

def to_key
  if persisted?
    key = parent_config.nil? ? [] : parent_config.to_key
    key << self.class.config_name
  else
    nil
  end
end

#to_paramObject



30
31
32
33
34
35
36
# File 'lib/configure_me/base.rb', line 30

def to_param
  if persisted?
    to_key.join('-')
  else
    nil
  end
end