Class: Mint::Resource
- Inherits:
-
Object
- Object
- Mint::Resource
- Defined in:
- lib/mint/resource.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#name ⇒ Object
Returns the value of attribute name.
-
#root ⇒ Object
Returns the value of attribute root.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #destination_directory ⇒ Object
- #destination_directory_path ⇒ Object
- #destination_file ⇒ Object
- #destination_file_path ⇒ Object
- #equal?(other) ⇒ Boolean (also: #==)
-
#initialize(source, options = {}) {|_self| ... } ⇒ Resource
constructor
A new instance of Resource.
- #render(context = Object.new, args = {}) ⇒ Object
- #renderer=(renderer) ⇒ Object
- #root_directory ⇒ Object
- #root_directory_path ⇒ Object
- #source_directory ⇒ Object
- #source_directory_path ⇒ Object
- #source_file ⇒ Object
- #source_file_path ⇒ Object
Constructor Details
#initialize(source, options = {}) {|_self| ... } ⇒ Resource
Returns a new instance of Resource.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mint/resource.rb', line 67 def initialize(source, ={}) return nil unless source self.type = :resource self.source = source self.root = [:root] || source_directory self.destination = [:destination] yield self if block_given? self.name = Mint.guess_name_from source self.renderer = Mint.renderer source end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
45 46 47 |
# File 'lib/mint/resource.rb', line 45 def destination @destination end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/mint/resource.rb', line 7 def name @name end |
#root ⇒ Object
Returns the value of attribute root.
12 13 14 |
# File 'lib/mint/resource.rb', line 12 def root @root end |
#source ⇒ Object
Returns the value of attribute source.
25 26 27 |
# File 'lib/mint/resource.rb', line 25 def source @source end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/mint/resource.rb', line 5 def type @type end |
Instance Method Details
#destination_directory ⇒ Object
59 60 61 |
# File 'lib/mint/resource.rb', line 59 def destination_directory destination_directory_path.to_s end |
#destination_directory_path ⇒ Object
55 56 57 |
# File 'lib/mint/resource.rb', line 55 def destination_directory_path destination_file_path.dirname end |
#destination_file ⇒ Object
51 52 53 |
# File 'lib/mint/resource.rb', line 51 def destination_file destination_file_path.to_s end |
#destination_file_path ⇒ Object
47 48 49 |
# File 'lib/mint/resource.rb', line 47 def destination_file_path root_directory_path + (destination || "") + name end |
#equal?(other) ⇒ Boolean Also known as: ==
81 82 83 |
# File 'lib/mint/resource.rb', line 81 def equal?(other) self.destination_file_path == other.destination_file_path end |
#render(context = Object.new, args = {}) ⇒ Object
86 87 88 89 |
# File 'lib/mint/resource.rb', line 86 def render(context=Object.new, args={}) # see Tilt TEMPLATES.md for more info @renderer.render context, args end |
#renderer=(renderer) ⇒ Object
63 64 65 |
# File 'lib/mint/resource.rb', line 63 def renderer=(renderer) @renderer = renderer end |
#root_directory ⇒ Object
21 22 23 |
# File 'lib/mint/resource.rb', line 21 def root_directory root_directory_path.to_s end |
#root_directory_path ⇒ Object
17 18 19 |
# File 'lib/mint/resource.rb', line 17 def root_directory_path Pathname.new(root || Dir.getwd). end |
#source_directory ⇒ Object
41 42 43 |
# File 'lib/mint/resource.rb', line 41 def source_directory source_directory_path.to_s end |
#source_directory_path ⇒ Object
37 38 39 |
# File 'lib/mint/resource.rb', line 37 def source_directory_path source_file_path.dirname end |
#source_file ⇒ Object
33 34 35 |
# File 'lib/mint/resource.rb', line 33 def source_file source_file_path.to_s end |
#source_file_path ⇒ Object
27 28 29 30 31 |
# File 'lib/mint/resource.rb', line 27 def source_file_path path = Pathname.new(source) path.absolute? ? path. : root_directory_path + path end |