Class: IntercomRails::ConfigSingleton
- Inherits:
-
Object
- Object
- IntercomRails::ConfigSingleton
- Defined in:
- lib/intercom-rails/config.rb
Direct Known Subclasses
Class Method Summary collapse
- .config_accessor(*args, &block) ⇒ Object
- .config_group(name, &block) ⇒ Object
- .config_reader(name) ⇒ Object
- .config_writer(name, &block) ⇒ Object
- .meta_class ⇒ Object
Class Method Details
.config_accessor(*args, &block) ⇒ Object
7 8 9 10 |
# File 'lib/intercom-rails/config.rb', line 7 def self.config_accessor(*args, &block) config_reader(*args) config_writer(*args, &block) end |
.config_group(name, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/intercom-rails/config.rb', line 35 def self.config_group(name, &block) camelized_name = name.to_s.classify group = self.const_set(camelized_name, Class.new(self)) .send(:define_method, name) do group end group.send(:instance_variable_set, :@underscored_class_name, name) group.instance_eval(&block) end |
.config_reader(name) ⇒ Object
16 17 18 19 20 |
# File 'lib/intercom-rails/config.rb', line 16 def self.config_reader(name) .send(:define_method, name) do instance_variable_get("@#{name}") end end |
.config_writer(name, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/intercom-rails/config.rb', line 22 def self.config_writer(name, &block) .send(:define_method, "#{name}=") do |value| block.call(value) if block && (block.arity <= 1) if block && (block.arity > 1) field_name = underscored_class_name ? "#{underscored_class_name}.#{name}" : name block.call(value, field_name) end instance_variable_set("@#{name}", value) end end |
.meta_class ⇒ Object
12 13 14 |
# File 'lib/intercom-rails/config.rb', line 12 def self. class << self; self end end |