class Verbalize::Build

Attributes

default_keywords[R]
optional_keywords[R]
required_keywords[R]

Public Class Methods

call(required_keywords = [], optional_keywords = [], default_keywords = []) click to toggle source
# File lib/verbalize/build.rb, line 3
def self.call(required_keywords = [], optional_keywords = [], default_keywords = [])
  new(required_keywords, optional_keywords, default_keywords).call
end
new(required_keywords, optional_keywords, default_keywords) click to toggle source
# File lib/verbalize/build.rb, line 7
def initialize(required_keywords, optional_keywords, default_keywords)
  @required_keywords = required_keywords
  @optional_keywords = optional_keywords
  @default_keywords  = default_keywords
end

Public Instance Methods

call() click to toggle source
# File lib/verbalize/build.rb, line 13
    def call
      # We have to re-alias `!` to `call!` here, otherwise it will be pointing
      # to the original `call!` method
      <<-CODE
class << self
  def call(#{declaration_arguments_string})
    __proxied_call(#{forwarding_arguments_string})
  end

  def call!(#{declaration_arguments_string})
    __proxied_call!(#{forwarding_arguments_string})
  end
  alias_method :!, :call!
end

def initialize(#{declaration_arguments_string})
  #{initialize_body}
end

private

attr_reader #{attribute_readers_string}
      CODE
    end

Private Instance Methods

all_keywords() click to toggle source
# File lib/verbalize/build.rb, line 42
def all_keywords
  required_keywords + optional_keywords + default_keywords
end
attribute_readers_string() click to toggle source
# File lib/verbalize/build.rb, line 63
def attribute_readers_string
  all_keywords.map { |keyword| ":#{keyword}" }.join(', ')
end
declaration_arguments_string() click to toggle source
# File lib/verbalize/build.rb, line 46
def declaration_arguments_string
  required_segments  = required_keywords.map { |kw| "#{kw}:" }
  optional_segments  = optional_keywords.map { |kw| "#{kw}: nil" }
  default_segments   = default_keywords.map  { |kw| "#{kw}: self.defaults[:#{kw}].call" }
  (required_segments + optional_segments + default_segments).join(', ')
end
forwarding_arguments_string() click to toggle source
# File lib/verbalize/build.rb, line 53
def forwarding_arguments_string
  all_keywords.map { |keyword| "#{keyword}: #{keyword}" }.join(', ')
end
initialize_body() click to toggle source
# File lib/verbalize/build.rb, line 57
def initialize_body
  all_keywords.map do |keyword|
    "__setup(:#{keyword}, #{keyword})"
  end.join("\n  ")
end