Class: Rapid::Setting::Definer

Inherits:
Object
  • Object
show all
Defined in:
lib/rapid/setting/definer.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, options = {}) ⇒ Definer

Returns a new instance of Definer.



6
7
8
9
# File 'lib/rapid/setting/definer.rb', line 6

def initialize klass, options = {}
  @klass = klass
  @delimiter = '.'
end

Instance Method Details

#boolean(full_name, options = {}) ⇒ Object



11
12
13
14
15
# File 'lib/rapid/setting/definer.rb', line 11

def boolean full_name, options = {}
  namespace, name = find_namespace_and_name full_name
  setting = BooleanSetting.new name, options.merge(:namespace => namespace)
  define_setting setting
end

#class_eval(namespace_name, &block) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/rapid/setting/definer.rb', line 41

def class_eval namespace_name, &block
  names = namespace_name.to_s.split('.')
  namespace = find_namespace *names
  raise ArgumentError.new("namespace not found: #{namespace_name.inspect}") unless namespace
  raise ArgumentError.new("namespace does not have a custom class") unless namespace.instance_class
  namespace.instance_class.class_eval &block
end

#code(full_name, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/rapid/setting/definer.rb', line 35

def code full_name, options = {}
  namespace, name = find_namespace_and_name full_name
  setting = StringSetting.new name, options.merge(:namespace => namespace)
  define_setting setting
end

#find_namespace(*names) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rapid/setting/definer.rb', line 49

def find_namespace *names
  namespace = nil
  names.each_with_index do |name, index|
    if index == 0
      namespace = @klass.settings[name]
    elsif namespace
      namespace = namespace[name]
    end
  end
  namespace
end

#inspectObject



61
62
63
# File 'lib/rapid/setting/definer.rb', line 61

def inspect
  %(#<Rapid::Setting::Definer>)
end

#integer(full_name, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/rapid/setting/definer.rb', line 23

def integer full_name, options = {}
  namespace, name = find_namespace_and_name full_name
  setting = IntegerSetting.new name, options.merge(:namespace => namespace)
  define_setting setting
end

#namespace(full_name, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/rapid/setting/definer.rb', line 29

def namespace full_name, options = {}
  namespace, name = find_namespace_and_name full_name
  setting = Namespace::Base.new name, options.merge(:namespace => namespace, :class => @klass)
  define_setting setting
end

#string(full_name, options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/rapid/setting/definer.rb', line 17

def string full_name, options = {}
  namespace, name = find_namespace_and_name full_name
  setting = StringSetting.new name, options.merge(:namespace => namespace)
  define_setting setting
end