Module: Aska::ClassMethods

Defined in:
lib/aska.rb

Instance Method Summary collapse

Instance Method Details

#are_rules?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/aska.rb', line 31

def are_rules?(name)
  !look_up_rules(name).empty?
end

#aska_attr_accessorsObject



34
35
36
# File 'lib/aska.rb', line 34

def aska_attr_accessors
  @aska_attr_accessors ||= Rules.new
end

#aska_named(name) ⇒ Object



40
41
42
# File 'lib/aska.rb', line 40

def aska_named(name)
  "#{name}_aska"
end

#create_instance_variable(k) ⇒ Object



23
24
25
26
27
# File 'lib/aska.rb', line 23

def create_instance_variable(k)
  aska_attr_accessors << k.to_sym unless aska_attr_accessors.include?(k.to_sym)
  attr_reader k.to_sym unless respond_to?("#{k}".to_sym)
  attr_writer k.to_sym unless respond_to?("#{k}=".to_sym)
end

#defined_rulesObject



37
38
39
# File 'lib/aska.rb', line 37

def defined_rules
  @defined_rules ||= {}
end

#look_up_rules(name) ⇒ Object



28
29
30
# File 'lib/aska.rb', line 28

def look_up_rules(name)
  defined_rules[name.to_sym] ||= Rules.new
end

#rules(name = :rules, arr = []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/aska.rb', line 7

def rules(name=:rules, arr=[])
  returning look_up_rules(name) do |rs|
    arr.each do |line|
      next unless line
      k = line[/(.+)[=\\\<\>](.*)/, 1].gsub(/\s+/, '')
      v = line[/(.+)[=\\<>](.*)/, 2].gsub(/\s+/, '')
      m = line[/[=\\<>]/, 0].gsub(/\s+/, '')
      
      create_instance_variable(k)
      rs << {k => [m, v]}
    end
    self.send(:define_method, name) do
      look_up_rules(name)
    end        
  end
end