Module: Pedlar

Includes:
Forwardable
Defined in:
lib/pedlar.rb,
lib/pedlar/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#peddles(*brands) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pedlar.rb', line 11

def peddles(*brands)
  # do we have a list of interface to setup
  # or one interface with an alias ?
  brands = [brands] unless brands.all? { |brand| brand.is_a? Class }

  # Ruby is too nice a pal... It accepts to assign iteration
  # variables in a juicy DWIM way : depending on the arguments
  # we got, `brands` is either a flat list of classes
  # or a list of one list. But it's the same to my pal...
  brands.each do |brand, as|
    # lousy lousy active_support neat methods mockery
    as ||= brand.to_s.downcase.gsub('::', '_')

    # three class methods per `brand` to setup accessors/mutators.
    %w|accessor writer reader|.each do |type|
      # ex: brand=Date defines `date_accessor`, `date_writer`, `date_reader`.
      # Each of these three calls private methods (`type`) setting up
      # the actual accessor/mutator with user-defined name.
      define_singleton_method "#{as}_#{type}".to_sym do |*accessors|
        # `accessors` below being the user-defined accessors names.
        accessors.each do |accessor|
          send type, brand, accessor
        end
      end
    end
  end
end

#safe_delegator(delegate, delegation, method = delegation) ⇒ Object

hand-made delegation setup



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

def safe_delegator(delegate, delegation, method=delegation)
  safe_delegation delegate, delegation, method
end

#safe_delegators(delegate, *delegations) ⇒ Object

hand-made delegations setup



45
46
47
# File 'lib/pedlar.rb', line 45

def safe_delegators(delegate, *delegations)
  delegations.each { |d| safe_delegation delegate, d }
end