Class: Cleon::Decor

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/cleon/decor.rb

Overview

Decorator for model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, root = '') ⇒ Decor

Returns a new instance of Decor.


9
10
11
12
# File 'lib/cleon/decor.rb', line 9

def initialize(object, root = '')
  super(object)
  @root = root
end

Instance Attribute Details

#rootObject (readonly) Also known as: root_const

Returns the value of attribute root.


7
8
9
# File 'lib/cleon/decor.rb', line 7

def root
  @root
end

Instance Method Details

#argumentsString

Returns :params presentation as method arguments.

Returns:

  • (String)

    :params presentation as method arguments


42
43
44
45
# File 'lib/cleon/decor.rb', line 42

def arguments
  return '' if params.empty?
  params.map(&:name).join(', ')
end

#at_argumentsString

Returns :params presentation as method “at” - arguments.

Returns:

  • (String)

    :params presentation as method “at” - arguments


48
49
50
51
# File 'lib/cleon/decor.rb', line 48

def at_arguments
  return '' if params.empty?
  params.map(&:name).map{|p| "@#{p}"}.join(', ')
end

#attributesObject


59
60
61
62
# File 'lib/cleon/decor.rb', line 59

def attributes
  retrun '' if params.empty?
  params.map(&:name).map{|a| "attr_reader :#{a}"}.join(?\n) + "\n"
end

#constObject

Returns ruby const from @name.

Returns:

  • ruby const from @name


15
16
17
# File 'lib/cleon/decor.rb', line 15

def const
  constanize(name)
end

#constanize(str) ⇒ Object


37
38
39
# File 'lib/cleon/decor.rb', line 37

def constanize(str)
  sanitize(str).split(?_).map(&:capitalize).join
end

#keyword_argumentsString

Returns :params presentation as method keywword arguments.

Returns:

  • (String)

    :params presentation as method keywword arguments


54
55
56
57
# File 'lib/cleon/decor.rb', line 54

def keyword_arguments
  return '' if params.empty?
  params.map(&:name).join(':, ') + ':'
end

#sanitize(str) ⇒ Object


33
34
35
# File 'lib/cleon/decor.rb', line 33

def sanitize(str)
  str.downcase.strip.gsub(/\s{1,}/, '_')
end

#sourceObject

def root_const

constanize(root)

end


25
26
27
# File 'lib/cleon/decor.rb', line 25

def source
  "#{sanitize(name)}.rb"
end

#specObject


29
30
31
# File 'lib/cleon/decor.rb', line 29

def spec
  "#{sanitize(name)}_spec.rb"
end