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_nameObject



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

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



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

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

.inherited(subclass) ⇒ Object



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

def inherited(subclass)
  super
  configs << subclass
end

Instance Method Details

#config_keyObject



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

def config_key
  to_param
end

#persisted?Boolean

Returns:

  • (Boolean)


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

def persisted?
  true
end

#storage_key(name) ⇒ Object



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

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

#to_keyObject



21
22
23
24
25
26
27
28
29
# 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
    key
  else
    nil
  end
end

#to_paramObject



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

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