Class: CheckPlease::Flags

Inherits:
Object
  • Object
show all
Includes:
Reification
Defined in:
lib/check_please/flags.rb

Overview

NOTE: this gets all of its attributes defined (via .define) in ../check_please.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reification

included

Constructor Details

#initialize(attrs = {}) ⇒ Flags

Returns a new instance of Flags.



41
42
43
44
45
46
# File 'lib/check_please/flags.rb', line 41

def initialize(attrs = {})
  @attributes = {}
  attrs.each do |name, value|
    send "#{name}=", value
  end
end

Class Method Details

.[](name) ⇒ Object



11
12
13
# File 'lib/check_please/flags.rb', line 11

def self.[](name)
  BY_NAME[name.to_sym]
end

.define(name, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/check_please/flags.rb', line 15

def self.define(name, &block)
  flag = Flag.new(name: name.to_sym, &block)
  BY_NAME[flag.name] = flag
  define_accessors flag

  nil
end

.define_accessors(flag) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/check_please/flags.rb', line 29

def self.define_accessors(flag)
  getter = flag.name
  define_method(getter) {
    @attributes.fetch(flag.name) { flag.default }
  }

  setter = :"#{flag.name}="
  define_method(setter) { |value|
    flag.send :__set__, value, on: @attributes, flags: self
  }
end

.each_flagObject



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

def self.each_flag
  BY_NAME.each do |_, flag|
    yield flag
  end
end