Class: Cleon::Decor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Cleon::Decor
- Defined in:
- lib/cleon/decor.rb
Overview
Decorator for model.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
(also: #root_const)
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#arguments ⇒ String
:params presentation as method arguments.
-
#at_arguments ⇒ String
:params presentation as method “at” - arguments.
- #attributes ⇒ Object
-
#const ⇒ Object
Ruby const from @name.
- #constanize(str) ⇒ Object
-
#initialize(object, root = '') ⇒ Decor
constructor
A new instance of Decor.
-
#keyword_arguments ⇒ String
:params presentation as method keywword arguments.
- #sanitize(str) ⇒ Object
-
#source ⇒ Object
def root_const constanize(root) end.
- #spec ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (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
#arguments ⇒ String
Returns :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_arguments ⇒ String
Returns :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 |
#attributes ⇒ Object
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 |
#const ⇒ Object
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_arguments ⇒ String
Returns :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 |
#source ⇒ Object
25 26 27 |
# File 'lib/cleon/decor.rb', line 25 def source "#{sanitize(name)}.rb" end |
#spec ⇒ Object
29 30 31 |
# File 'lib/cleon/decor.rb', line 29 def spec "#{sanitize(name)}_spec.rb" end |