Class: CouchDocs::DesignDirectory
- Inherits:
-
Object
- Object
- CouchDocs::DesignDirectory
- Defined in:
- lib/couch_docs/design_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) ⇒ DesignDirectory
constructor
A new instance of DesignDirectory.
- #to_hash ⇒ Object
Constructor Details
#initialize(path) ⇒ DesignDirectory
Returns a new instance of DesignDirectory.
23 24 25 26 |
# File 'lib/couch_docs/design_directory.rb', line 23 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.
12 13 14 |
# File 'lib/couch_docs/design_directory.rb', line 12 def couch_view_dir @couch_view_dir end |
Class Method Details
.a_to_hash(a) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/couch_docs/design_directory.rb', line 14 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
36 37 38 39 40 41 42 43 44 |
# File 'lib/couch_docs/design_directory.rb', line 36 def (filename) File.dirname(filename). gsub(/#{couch_view_dir}\/?/, ''). split(/\//) + [ File.basename(filename, '.js'), File.new(filename).read ] end |
#to_hash ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/couch_docs/design_directory.rb', line 28 def to_hash Dir["#{couch_view_dir}/**/*.js"].inject({}) do |memo, filename| DesignDirectory. a_to_hash((filename)). deep_merge(memo) end end |