Class: CouchDesignDocs::Directory
- Inherits:
-
Object
- Object
- CouchDesignDocs::Directory
- Defined in:
- lib/couch_design_docs/directory.rb
Instance Attribute Summary collapse
-
#couch_view_dir ⇒ Object
Returns the value of attribute couch_view_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #expand_file(filename) ⇒ Object
-
#initialize(path) ⇒ Directory
constructor
A new instance of Directory.
- #to_hash ⇒ Object
Constructor Details
#initialize(path) ⇒ Directory
25 26 27 28 |
# File 'lib/couch_design_docs/directory.rb', line 25 def initialize(path) Dir.new(path) # Just checkin' @couch_view_dir = path end |
Instance Attribute Details
#couch_view_dir ⇒ Object
Returns the value of attribute couch_view_dir.
14 15 16 |
# File 'lib/couch_design_docs/directory.rb', line 14 def couch_view_dir @couch_view_dir end |
Class Method Details
.a_to_hash(a) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/couch_design_docs/directory.rb', line 16 def self.a_to_hash(a) key = a.first if (a.length > 2) { key => a_to_hash(a[1,a.length]) } else { key => a.last } end end |
Instance Method Details
#expand_file(filename) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/couch_design_docs/directory.rb', line 38 def (filename) File.dirname(filename). gsub(/#{couch_view_dir}\/?/, ''). split(/\//) + [ File.basename(filename, '.js'), File.new(filename).read ] end |
#to_hash ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/couch_design_docs/directory.rb', line 30 def to_hash Dir["#{couch_view_dir}/**/*.js"].inject({}) do |memo, filename| Directory. a_to_hash((filename)). deep_merge(memo) end end |