yamlir 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yamlir.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Evgeniy Fateev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ # YAMLir
2
+
3
+ YAMLir - is a simple library for generating folders structure in [YAML](http://www.yaml.org/) format. For example:
4
+
5
+ books
6
+ ├── architecture
7
+ │   └── event-driven
8
+ │      ├── event_driven_programming.pdf
9
+ │      ├── eventmachine_introduction_10.pdf
10
+ │      └── eventmachine_presentation.pdf
11
+ ├── rails
12
+ │   └── Rails.3.in.Action.pdf
13
+ └── ruby
14
+ ├── Design Patterns in Ruby.pdf
15
+ └── RubyMethodLookupFlow.pdf
16
+
17
+ And the same structure with YAMLir:
18
+
19
+ ---
20
+ books:
21
+ architecture:
22
+ event-driven:
23
+ event_driven_programming.pdf:
24
+ eventmachine_introduction_10.pdf:
25
+ eventmachine_presentation.pdf:
26
+ rails:
27
+ Rails.3.in.Action.pdf:
28
+ ruby:
29
+ Design Patterns in Ruby.pdf:
30
+ RubyMethodLookupFlow.pdf:
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ gem 'yamlir'
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install yamlir
45
+
46
+ ## Usage
47
+
48
+ YAMLir.generate
49
+
50
+ This code will create *yamlir.yml* file in the current directory with the recursive structure of it.
51
+
52
+ ## Options
53
+
54
+ It's possible to change some things.
55
+
56
+ To change *<a href="http://en.wikipedia.org/wiki/Glob_(programming)">glob</a>* pattern:
57
+
58
+ YAMLir.generate glob: "{app/{models},lib}/**/*"
59
+
60
+ For custom *output file* name (default is yamlir.yml):
61
+
62
+ YAMLir.generate file: "result.yml"
63
+
64
+ For change *output directory* path (missing directories will be created):
65
+
66
+ YAMLir.generate path: "/tmp/structure"
67
+
68
+ ## Custom modes
69
+
70
+ ### Foreword
71
+
72
+ YAMLir can be augmented by custom modes.
73
+
74
+ Originally this gem was conceived like a tool for generating a list of rails application files for subsequent marks those of them that have been tested and start the corresponding test suites. That's why YAMLir includes *RailsTestCover* mode which generates rails *app* directory structure and puts the result file (named *cover.yml*) in the *test* or *spec* folder. Later this idea was realized in a more general form with the possibility of adding custom modes.
75
+
76
+ ### Create own mode
77
+
78
+ Suppose we want to create mode that generates all mp3 files under Music directory. This is it:
79
+
80
+ # lib/yamlir/mode/mp3.rb
81
+
82
+ module YAMLir
83
+
84
+ class Mp3 < Base
85
+
86
+ @glob = "/home/psylone/Music/**/*.{mp3}"
87
+ @file = "mp3.yml"
88
+ @path = "."
89
+
90
+ end
91
+
92
+ end
93
+
94
+ To generate YAML structure write:
95
+
96
+ YAMLir::Mp3.generate
97
+
98
+ All this work can also be done using options with *YAMLir.generate* method.
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yamlir'
@@ -0,0 +1,18 @@
1
+ require "yamlir/sorted_list"
2
+ require "yamlir/tree"
3
+ require "yamlir/mode"
4
+ require "yamlir/version"
5
+
6
+ module YAMLir
7
+
8
+ def self.generate options = {}
9
+ Simple.generate options
10
+ end
11
+
12
+ # def self.register! options
13
+ # TODO register new mode
14
+ #
15
+ # YAMLir.register! name: "Sinatra", glob: "", file: "", path: ""
16
+ # end
17
+
18
+ end
@@ -0,0 +1,58 @@
1
+ require "set"
2
+ require "yaml"
3
+ require "fileutils"
4
+
5
+ module YAMLir
6
+
7
+ class Base
8
+
9
+ module ClassMethods
10
+
11
+ def generate options = {}
12
+ # TODO: Add options:
13
+ # recursive: "true or false recursive"
14
+ # folder_only: "get folders only"
15
+ # without_extensions: "true of false for extensions" There'll be problem for the folder with the same name as the file without extension
16
+ # store: true or false - store or not result in file
17
+ @glob = normalize options[:glob] || @glob
18
+ @file = normalize options[:file] || @file
19
+ @path = normalize options[:path] || @path
20
+ store process Dir[*@glob]
21
+ end
22
+
23
+
24
+ private
25
+
26
+ def store result
27
+ @path.chomp! "/"
28
+ FileUtils.mkdir_p @path
29
+ name = [@path, @file].join "/"
30
+ File.open(name, "w"){ |f| f.write result }
31
+ end
32
+
33
+ def process list
34
+ tree(seed list).to_yaml
35
+ end
36
+
37
+ def tree source
38
+ Tree.new(source).growth
39
+ end
40
+
41
+ def seed list
42
+ list = YAMLir::SortedList.sort(list)
43
+ Set.new(list).classify{ |name| File.dirname(name) }
44
+ end
45
+
46
+ def normalize opt
47
+ opt.is_a?(Proc) ? opt.call : opt
48
+ end
49
+
50
+ end
51
+
52
+ extend ClassMethods
53
+
54
+ end
55
+
56
+ end
57
+
58
+ Dir[File.expand_path("../mode", __FILE__).concat "/*.{rb}"].each{ |mode| require mode }
@@ -0,0 +1,13 @@
1
+ module YAMLir
2
+
3
+ class RailsTestCover < Base
4
+
5
+ @glob = "app/{controllers,helpers,mailers,models}/**/*"
6
+ @file = "cover.yml"
7
+ @path = Proc.new do
8
+ Dir.exist?("spec") ? "spec" : "test"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ module YAMLir
2
+
3
+ class Simple < Base
4
+
5
+ @glob = "**/*"
6
+ @file = "yamlir.yml"
7
+ @path = "."
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,28 @@
1
+ module YAMLir
2
+
3
+ module SortedList
4
+
5
+ module ClassMethods
6
+
7
+ def sort list
8
+ list.sort do |a, b|
9
+ if slashes(a) == slashes(b)
10
+ a <=> b
11
+ else
12
+ slashes(a) <=> slashes(b)
13
+ end
14
+ end
15
+ end
16
+
17
+ def slashes str
18
+ str.split("").select{ |char| char == "/" }.count
19
+ end
20
+ private :slashes
21
+
22
+ end
23
+
24
+ extend ClassMethods
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,44 @@
1
+ module YAMLir
2
+
3
+ class Tree
4
+
5
+ def initialize source
6
+ @source = source
7
+ @purpose = {}
8
+ end
9
+
10
+ def growth
11
+ for node, values in @source do create(node, values) end
12
+ @purpose
13
+ end
14
+
15
+
16
+ private
17
+
18
+ def create node, values
19
+ node = node.split "/"
20
+ traverse node, values
21
+ end
22
+
23
+ def traverse node, values
24
+ current_branch = @purpose
25
+ while node.length > 1
26
+ key = node.shift
27
+ current_branch.update key => {} unless current_branch[key]
28
+ current_branch = current_branch[key]
29
+ end
30
+ add current_branch, node.shift, values
31
+ end
32
+
33
+ def add branch, node, values
34
+ if node == "."
35
+ values.each{ |leaf| branch.update File.basename(leaf) => nil unless branch[leaf] || @source.keys.include?(leaf) }
36
+ else
37
+ branch[node] = {} unless branch[node]
38
+ values.each{ |leaf| branch[node].update File.basename(leaf) => nil unless @source.keys.include?(leaf) }
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,3 @@
1
+ module YAMLir
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'yamlir'
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe YAMLir do
4
+ it 'should have a version number' do
5
+ YAMLir::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should be_true
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yamlir/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yamlir"
8
+ spec.version = YAMLir::VERSION
9
+ spec.authors = ["Evgeniy Fateev"]
10
+ spec.email = ["spaceflow@gmail.com"]
11
+ spec.description = %q{Create YAML file (commonly named yamlir.yml) with folders content.}
12
+ spec.summary = %q{Generate folder structure in YAML format.}
13
+ spec.homepage = "https://github.com/psylone/yamlir"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yamlir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Evgeniy Fateev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Create YAML file (commonly named yamlir.yml) with folders content.
63
+ email:
64
+ - spaceflow@gmail.com
65
+ executables:
66
+ - yamlir
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - .travis.yml
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - bin/yamlir
78
+ - lib/yamlir.rb
79
+ - lib/yamlir/mode.rb
80
+ - lib/yamlir/mode/rails_test_cover.rb
81
+ - lib/yamlir/mode/simple.rb
82
+ - lib/yamlir/sorted_list.rb
83
+ - lib/yamlir/tree.rb
84
+ - lib/yamlir/version.rb
85
+ - spec/spec_helper.rb
86
+ - spec/yamlir_spec.rb
87
+ - yamlir.gemspec
88
+ homepage: https://github.com/psylone/yamlir
89
+ licenses:
90
+ - MIT
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: -4079057136267556810
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: -4079057136267556810
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.25
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Generate folder structure in YAML format.
119
+ test_files:
120
+ - spec/spec_helper.rb
121
+ - spec/yamlir_spec.rb