Class: Praxis::FileGroup
- Inherits:
-
Object
- Object
- Praxis::FileGroup
- Defined in:
- lib/praxis/file_group.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
Instance Method Summary collapse
- #[](*names) ⇒ Object
-
#initialize(base, &block) ⇒ FileGroup
constructor
A new instance of FileGroup.
- #layout(&block) ⇒ Object
- #map(name, pattern, &block) ⇒ Object
Constructor Details
#initialize(base, &block) ⇒ FileGroup
Returns a new instance of FileGroup.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/praxis/file_group.rb', line 7 def initialize(base, &block) if base.nil? raise ArgumentError, "base must not be nil." \ "Are you missing a call Praxis::Application.instance.setup?" end @groups = Hash.new @base = Pathname.new(base) if block_given? self.instance_eval(&block) end end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/praxis/file_group.rb', line 5 def base @base end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
5 6 7 |
# File 'lib/praxis/file_group.rb', line 5 def groups @groups end |
Instance Method Details
#[](*names) ⇒ Object
39 40 41 |
# File 'lib/praxis/file_group.rb', line 39 def [](*names) names.inject(@groups) { |group, name| group[name] || [] } end |
#layout(&block) ⇒ Object
22 23 24 |
# File 'lib/praxis/file_group.rb', line 22 def layout(&block) self.instance_eval(&block) end |
#map(name, pattern, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/praxis/file_group.rb', line 26 def map(name, pattern, &block) return unless base.exist? if block_given? @groups[name] = FileGroup.new(base + pattern, &block) else @groups[name] ||= [] files = Pathname.glob(base+pattern).select { |file| file.file? } files.sort_by! { |file| [file.to_s.split('/').size, file.to_s] } files.each { |file| @groups[name] << file } end end |