Module: AttrExtras::Mixin

Defined in:
lib/attr_extras/explicit.rb

Overview

Separate module so that mixing in the methods doesn't also mix in constants: thepugautomatic.com/2014/02/private-api/

Instance Method Summary collapse

Instance Method Details

#aattr_initialize(*names, &block) ⇒ Object Also known as: attr_accessor_initialize


57
58
59
60
# File 'lib/attr_extras/explicit.rb', line 57

def aattr_initialize(*names, &block)
  attr_initialize(*names, &block)
  attr_accessor(*Utils.flat_names(names))
end

#attr_id_query(*names) ⇒ Object


80
81
82
# File 'lib/attr_extras/explicit.rb', line 80

def attr_id_query(*names)
  AttrQuery.define_with_suffix(self, "_id", *names)
end

#attr_implement(*names) ⇒ Object


84
85
86
# File 'lib/attr_extras/explicit.rb', line 84

def attr_implement(*names)
  AttrImplement.new(self, names).apply
end

#attr_initialize(*names, &block) ⇒ Object


19
20
21
# File 'lib/attr_extras/explicit.rb', line 19

def attr_initialize(*names, &block)
  AttrInitialize.new(self, names, block).apply
end

#attr_private(*names) ⇒ Object


23
24
25
26
27
28
29
30
# File 'lib/attr_extras/explicit.rb', line 23

def attr_private(*names)
  # Need this to avoid "private attribute?" warnings when running
  # the full test suite; not sure why exactly.
  public

  attr_reader(*names)
  private(*names)
end

#attr_query(*names) ⇒ Object


76
77
78
# File 'lib/attr_extras/explicit.rb', line 76

def attr_query(*names)
  AttrQuery.define_with_suffix(self, "", *names)
end

#attr_value(*names) ⇒ Object


32
33
34
# File 'lib/attr_extras/explicit.rb', line 32

def attr_value(*names)
  AttrValue.new(self, *names).apply
end

#method_object(*names) ⇒ Object


72
73
74
# File 'lib/attr_extras/explicit.rb', line 72

def method_object(*names)
  static_facade :call, *names
end

#pattr_initialize(*names, &block) ⇒ Object Also known as: attr_private_initialize


36
37
38
39
# File 'lib/attr_extras/explicit.rb', line 36

def pattr_initialize(*names, &block)
  attr_initialize(*names, &block)
  attr_private(*Utils.flat_names(names))
end

#rattr_initialize(*names, &block) ⇒ Object Also known as: attr_reader_initialize


50
51
52
53
# File 'lib/attr_extras/explicit.rb', line 50

def rattr_initialize(*names, &block)
  attr_initialize(*names, &block)
  attr_reader(*Utils.flat_names(names))
end

#static_facade(method_name, *names) ⇒ Object


64
65
66
67
68
69
70
# File 'lib/attr_extras/explicit.rb', line 64

def static_facade(method_name, *names)
  define_singleton_method(method_name) do |*values|
    new(*values).public_send(method_name)
  end

  pattr_initialize(*names)
end

#vattr_initialize(*names, &block) ⇒ Object Also known as: attr_value_initialize


43
44
45
46
# File 'lib/attr_extras/explicit.rb', line 43

def vattr_initialize(*names, &block)
  attr_initialize(*names, &block)
  attr_value(*Utils.flat_names(names))
end