Module: Qor::Dsl::ClassMethods

Defined in:
lib/qor_dsl/class_method.rb

Constant Summary collapse

@@lock =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#deep_find(*arguments, &block) ⇒ Object



60
61
62
# File 'lib/qor_dsl/class_method.rb', line 60

def deep_find(*arguments, &block)
  root.deep_find(*arguments, &block)
end

#default_configObject



28
29
30
31
32
33
34
# File 'lib/qor_dsl/class_method.rb', line 28

def default_config
  if @default_configs.is_a?(Array)
    @default_configs.select {|x| File.exist?(x.to_s) }[0]
  else
    @default_configs
  end
end

#default_configs(files) ⇒ Object



24
25
26
# File 'lib/qor_dsl/class_method.rb', line 24

def default_configs(files)
  @default_configs = files
end

#find(*arguments, &block) ⇒ Object



56
57
58
# File 'lib/qor_dsl/class_method.rb', line 56

def find(*arguments, &block)
  root.find(*arguments, &block)
end

#first(*arguments, &block) ⇒ Object



64
65
66
# File 'lib/qor_dsl/class_method.rb', line 64

def first(*arguments, &block)
  root.first(*arguments, &block)
end

#load(path = nil, opts = {}, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/qor_dsl/class_method.rb', line 36

def load(path=nil, opts={}, &block)
  @@lock.synchronize do
    reset! if opts[:force] || block_given?

    @root ||= if block_given? # Load from block
                node_root.config.instance_eval(&block)
                node_root
              else # Load from file
                @load_path = path || @load_path || default_config
                load_file(@load_path)
              end
  end
end

#load_file(file) ⇒ Object



50
51
52
53
54
# File 'lib/qor_dsl/class_method.rb', line 50

def load_file(file)
  raise Qor::Dsl::ConfigurationNotFound unless File.exist?(file.to_s)
  node_root.config.instance_eval(File.read(file))
  node_root
end

#node(type, options = {}, &blk) ⇒ Object



16
17
18
# File 'lib/qor_dsl/class_method.rb', line 16

def node(type, options={}, &blk)
  node_root.node(type, options, &blk)
end

#node_rootObject



5
6
7
# File 'lib/qor_dsl/class_method.rb', line 5

def node_root
  @node_root ||= Qor::Dsl::Node.new
end

#reset!Object



9
10
11
12
13
14
# File 'lib/qor_dsl/class_method.rb', line 9

def reset!
  node_config = node_root.config
  @node_root = Qor::Dsl::Node.new
  @node_root.add_config(node_config)
  @root = nil
end

#rootObject



20
21
22
# File 'lib/qor_dsl/class_method.rb', line 20

def root
  @root || load
end