Module: Consul::Power::DynamicAccess::InstanceMethods

Included in:
Consul::Power
Defined in:
lib/consul/power/dynamic_access.rb

Instance Method Summary collapse

Instance Method Details

#for_model(*args) ⇒ Object



59
60
61
# File 'lib/consul/power/dynamic_access.rb', line 59

def for_model(*args)
  send(name_for_model(*args))
end

#include!(power_name, *args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/consul/power/dynamic_access.rb', line 16

def include!(power_name, *args)
  warn "makandra/consul: #include! is deprececated. Use #include_power! and #include_object! instead."
  if args.size == 0
    include_power!(power_name, *args)
  else
    include_object!(power_name, *args)
  end
end

#include?(power_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
# File 'lib/consul/power/dynamic_access.rb', line 7

def include?(power_name, *args)
  warn "makandra/consul: #include? is deprececated. Use #include_power? and #include_object? instead."
  if args.size == 0
    include_power?(power_name, *args)
  else
    include_object?(power_name, *args)
  end
end

#include_model!(*args) ⇒ Object



67
68
69
# File 'lib/consul/power/dynamic_access.rb', line 67

def include_model!(*args)
  include_power!(name_for_model(*args))
end

#include_model?(*args) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/consul/power/dynamic_access.rb', line 63

def include_model?(*args)
  include_power?(name_for_model(*args))
end

#include_object!(power_name, *context_and_object) ⇒ Object



38
39
40
41
# File 'lib/consul/power/dynamic_access.rb', line 38

def include_object!(power_name, *context_and_object)
  power_name = power_name.to_s
  send("#{singularize_power_name(power_name)}!", *context_and_object)
end

#include_object?(power_name, *context_and_object) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/consul/power/dynamic_access.rb', line 33

def include_object?(power_name, *context_and_object)
  power_name = power_name.to_s
  send("#{singularize_power_name(power_name)}?", *context_and_object)
end

#include_power!(power_name, *context) ⇒ Object



29
30
31
# File 'lib/consul/power/dynamic_access.rb', line 29

def include_power!(power_name, *context)
  send("#{power_name}!", *context)
end

#include_power?(power_name, *context) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/consul/power/dynamic_access.rb', line 25

def include_power?(power_name, *context)
  send("#{power_name}?", *context)
end

#include_record!(*args) ⇒ Object



48
49
50
51
# File 'lib/consul/power/dynamic_access.rb', line 48

def include_record!(*args)
  adjective, record = Util.adjective_and_argument(*args)
  include_object!(name_for_model(adjective, record.class), record)
end

#include_record?(*args) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/consul/power/dynamic_access.rb', line 43

def include_record?(*args)
  adjective, record = Util.adjective_and_argument(*args)
  include_object?(name_for_model(adjective, record.class), record)
end

#name_for_model(*args) ⇒ Object



53
54
55
56
57
# File 'lib/consul/power/dynamic_access.rb', line 53

def name_for_model(*args)
  adjective, model_class = Util.adjective_and_argument(*args)
  collection_name = model_class.name.underscore.gsub('/', '_').pluralize
  [adjective, collection_name].select(&:present?).join('_')
end