outline 0.1.5 → 0.2.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- outline (0.1.3)
4
+ outline (0.2.0)
5
5
  meta_tools (~> 0.2.6)
6
6
 
7
7
  GEM
@@ -0,0 +1,49 @@
1
+ require 'pathname'
2
+ __LIB__ = Pathname.new(__FILE__).expand_path.dirname.join('lib').to_s
3
+ $:.unshift(__LIB__) unless $:.include?(__LIB__)
4
+ require 'outline'
5
+
6
+ def notify(message)
7
+ start_time = Time.now
8
+ puts "-- #{message}"
9
+ yield
10
+ puts " -> #{'%0.04f' % (Time.now - start_time)}s"
11
+ end
12
+
13
+ namespace :gem do
14
+ desc 'Update the VERSION file to the latest version'
15
+ task :update_version do
16
+ notify 'Updating VERSION' do
17
+ File.open('VERSION', 'w+') { |f| f.print Outline::VERSION }
18
+ end
19
+ end
20
+
21
+ desc 'Build the gem'
22
+ task :build do
23
+ notify 'Building gem' do
24
+ `gem build *.gemspec`
25
+ end
26
+ end
27
+
28
+ desc 'Push the gem to RubyGems'
29
+ task :push do
30
+ notify 'Pushing gem' do
31
+ `gem push *.gem`
32
+ end
33
+ end
34
+
35
+ desc 'Move the gem to the pkg directory'
36
+ task :move do
37
+ notify 'Moving gem' do
38
+ `mv *.gem pkg/`
39
+ end
40
+ end
41
+
42
+ desc 'Update VERSION, build the gem, push the gem, then move the gem to the pkg directory'
43
+ task deploy: [:update_version, :build, :push, :move]
44
+ end
45
+
46
+ desc "Run all specs"
47
+ task :spec do
48
+ sh 'bundle exec rspec spec'
49
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.2.0
@@ -3,114 +3,93 @@ require 'meta_tools'
3
3
 
4
4
  class Hash
5
5
  def to_outline
6
+ convert_data = Proc.new do |data|
7
+ data.each_with_object({}) do |(key, value), memo|
8
+ if value.respond_to?(:to_hash) || value.respond_to?(:to_h)
9
+ value = value.respond_to?(:to_hash) ? value.to_hash : value.to_h
10
+ value = value.to_outline
11
+ end
12
+
13
+ memo[key] = value
14
+ end
15
+ end
16
+
17
+ data = convert_data[ self ]
6
18
 
19
+ Outline.new(data: data)
7
20
  end
8
21
  end
9
22
 
10
23
  class Outline
11
- undef_method :abort
12
- undef_method :at_exit
13
- undef_method :autoload
14
- undef_method :autoload?
15
- undef_method :binding
16
- undef_method :caller
17
- undef_method :catch
18
- undef_method :exit
19
- undef_method :exit!
20
- undef_method :fail
21
- undef_method :fork
22
- undef_method :format
23
- undef_method :gets
24
- undef_method :global_variables
25
- undef_method :loop
26
- undef_method :open
27
- undef_method :p
28
- undef_method :print
29
- undef_method :printf
30
- undef_method :raise
31
- undef_method :rand
32
- undef_method :readline
33
- undef_method :readlines
34
- undef_method :require
35
- undef_method :require_relative
36
- undef_method :select
37
- undef_method :set_trace_func
38
- undef_method :sleep
39
- undef_method :spawn
40
- undef_method :sprintf
41
- undef_method :srand
42
- undef_method :syscall
43
- undef_method :system
44
- undef_method :test
45
- undef_method :throw
46
- undef_method :trace_var
47
- undef_method :trap
48
- undef_method :untrace_var
49
- undef_method :warn
50
-
51
- class ArgumentWithBlockError < StandardError
52
- def to_s; "You cannot give an argument with a block"; end
53
- end
24
+ VERSION = '0.2.0'
54
25
 
26
+ # It's as if we are subclassing BasicObject, but without the loss of context (and object_id):
27
+ (Object.instance_methods - BasicObject.instance_methods).each { |meth| remove_method(meth) unless [:object_id].include?(meth) rescue nil }
55
28
  include MetaTools
56
29
 
57
30
  attr_reader :parent, :data
58
31
 
59
32
  def initialize(opts={}, &blk)
60
33
  raise(TypeError, "opts must respond to :to_hash or be nil") unless opts.nil? || opts.respond_to?(:to_hash)
61
- raise(TypeError, "opts[:data] must respond to :to_h or :to_hash or be nil") unless opts.nil? || opts.respond_to?(:to_hash) || opts.respond_to?(:to_h)
34
+ raise(TypeError, "opts[:data] must respond to :to_h or :to_hash or be nil") unless opts[:data].nil? || opts[:data].respond_to?(:to_hash) || opts[:data].respond_to?(:to_h)
62
35
 
63
36
  opts = opts.to_hash
64
-
65
- # Check to see if incoming data is already an outline
66
- # if so, then turn it into a hash
67
-
68
37
  data = opts[:data].respond_to?(:to_hash) ? opts[:data].to_hash : opts[:data].to_h unless opts[:data].nil?
69
38
 
70
39
  @parent = opts[:parent]
71
40
  @data = data
72
- @data ||= {}
41
+ @methods = []
73
42
 
74
- instance_eval(&blk) if block_given?
43
+ instance_eval(&blk) unless blk.nil?
75
44
  end
76
45
 
77
46
  def method_missing(meth, *args, &blk)
78
47
  meth = meth.to_s.gsub(/=$/, '').to_sym if meth =~ /=$/
79
48
 
80
- meta_def(meth) do |value=nil, &blk|
81
- block_given, value_given = !blk.nil?, !value.nil?
49
+ unless @methods.include?(meth)
50
+ @methods << meth
82
51
 
83
- if !block_given && !value_given
84
- @data[meth] = Outline.new(parent: self) unless @data.has_key?(meth)
52
+ meta_def(meth) do |*values, &blk|
53
+ block_given, values_given = !blk.nil?, !values.empty?
54
+ @data ||= {}
85
55
 
86
- @data[meth]
87
- elsif block_given && value_given
88
- raise ArgumentWithBlockError
89
- elsif !block_given && value_given
90
- @data[meth] = value
91
- elsif block_given && !value_given
92
- @data[meth] = Outline.new(parent: self, &blk)
56
+ if !block_given && !values_given
57
+ @data[meth] = Outline.new(parent: self) unless @data.has_key?(meth)
58
+
59
+ @data[meth]
60
+ elsif block_given && values_given
61
+ data = values.delete_at(-1) if values.last.respond_to?(:to_hash) || values.last.respond_to?(:to_h)
62
+ data = { value: values.length == 1 ? values.first : values }.merge!(data || {})
63
+
64
+ @data[meth] = Outline.new(parent: self, data: data, &blk)
65
+ elsif !block_given && values_given
66
+ data = values.delete_at(-1) if values.last.respond_to?(:to_hash) || values.last.respond_to?(:to_h)
67
+
68
+ if data.nil?
69
+ @data[meth] = values.length == 1 ? values.first : values
70
+ else
71
+ data = { value: values.length == 1 ? values.first : values }.merge!(data || {}) unless values.empty?
72
+
73
+ @data[meth] = Outline.new(parent: self, data: data)
74
+ end
75
+ elsif block_given && !values_given
76
+ @data[meth] = Outline.new(parent: self, &blk)
77
+ end
93
78
  end
94
79
 
95
- end unless methods.include?(meth)
96
-
97
- meta_def("#{meth}=") { |value| send(meth, value) }
80
+ meta_def("#{meth}=") { |value| __send__(meth, value) }
81
+ end
98
82
 
99
- send(meth, *args, &blk)
83
+ __send__(meth, *args, &blk)
100
84
  end
101
85
 
102
86
  def to_h
103
- @data.inject({}) do |memo, (key, value)|
104
- memo[key] = value#.respond_to?(:to_h) ? value.to_h : value
105
- memo
87
+ @data ||= {}
88
+ @data.each_with_object({}) do |(key, value), memo|
89
+ memo[key] = value.respond_to?(:to_h) ? value.to_h : value
106
90
  end
107
91
  end
108
92
 
109
- def inspect
110
- "#<Outline:0x#{self.object_id.to_s(16)} @data=#{to_h}>"
111
- # "{O}#{to_h}"
112
- end
113
-
114
93
  # def to_json; end
115
94
  # def to_xml; end
116
95
  # def to_yaml; end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'outline'
2
2
 
3
3
  describe Outline do
4
4
  let(:config) do
@@ -12,23 +12,42 @@ describe Outline do
12
12
  remote "origin"
13
13
  end
14
14
 
15
- commands do
15
+ multiple 'foo', 'bar', 'baz'
16
+
17
+ commands say_hello: "echo 'Why, hello there'" do
16
18
  ssh "ssh deployer@#{parent.web.server}"
19
+
20
+ deploy Proc.new { "deploy completed" }
21
+ command :foo do
22
+ bar 'bar'
23
+ end
24
+
25
+ wget opts: '-a -b -c'
17
26
  end
18
27
 
19
- toggle
20
28
  some.deep.indented.config 'foo'
21
29
  end
22
30
  end
23
31
 
32
+ describe 'VERSION' do
33
+ it "should be correct" do
34
+ Outline::VERSION.should == '0.2.0'
35
+ end
36
+ end
37
+
24
38
  describe "getters" do
25
39
  it "should work" do
26
40
  config.testing.should == "testing"
27
41
  config.foo.should == "foo"
28
42
  proc { config.foo = "bar" }.call.should == "bar"
29
43
  config.timestamp_format.should == "%Y%m%d%H%M%S"
44
+ config.multiple.should == ['foo', 'bar', 'baz']
30
45
  config.some.deep.indented.config.should == 'foo'
31
46
  end
47
+
48
+ it 'should contain the correct methods' do
49
+ config.instance_eval { @methods }.should == [:foo, :timestamp_format, :web, :multiple, :commands, :some]
50
+ end
32
51
  end
33
52
 
34
53
  describe "#web" do
@@ -46,9 +65,14 @@ describe Outline do
46
65
  subject { config.commands }
47
66
  it { should be_a(Outline) }
48
67
 
49
- describe "#ssh" do
50
- subject { config.commands.ssh }
51
- it { should == "ssh deployer@my-proj.com" }
68
+ it "should return the correct values" do
69
+ config.commands.say_hello.should == "echo 'Why, hello there'"
70
+ config.commands.ssh.should == "ssh deployer@my-proj.com"
71
+ config.commands.deploy.class.should == Proc
72
+ config.commands.deploy.call.should == "deploy completed"
73
+ config.commands.command.value.should == :foo
74
+ config.commands.command.bar.should == 'bar'
75
+ config.commands.wget.opts.should == '-a -b -c'
52
76
  end
53
77
  end
54
78
 
@@ -62,28 +86,30 @@ describe Outline do
62
86
  end
63
87
 
64
88
  describe "#to_h" do
65
- # it "should return the correct Hash output" do
66
- # config.to_h.should == {
67
- # :testing => 'testing',
68
- # :foo => 'foo',
69
- # :timestamp_format => "%Y%m%d%H%M%S",
70
- # :web => {
71
- # :server => "my-proj.com",
72
- # :branch => "master",
73
- # :remote => "origin"
74
- # },
75
- # :commands => {
76
- # :ssh => "ssh deployer@my-proj.com"
77
- # },
78
- # :some => {
79
- # :deep => {
80
- # :indented => {
81
- # :config => 'foo'
82
- # }
83
- # }
84
- # }
85
- # }
86
- # end
89
+ it "should return the correct Hash output" do
90
+ config.to_h[:testing].should == "testing"
91
+ config.to_h[:foo].should == "foo"
92
+ config.to_h[:timestamp_format].should == "%Y%m%d%H%M%S"
93
+ config.to_h[:web].should == { server: "my-proj.com", branch: "master", remote: "origin" }
94
+ config.to_h[:multiple].should == ["foo", "bar", "baz"]
95
+ config.to_h[:commands].should be_a(Hash)
96
+ config.to_h[:commands][:say_hello].should == "echo 'Why, hello there'"
97
+ config.to_h[:commands][:ssh].should == "ssh deployer@my-proj.com"
98
+ config.to_h[:commands][:deploy].should be_a(Proc)
99
+ config.to_h[:commands][:command].should == { value: :foo, bar: "bar" }
100
+ config.to_h[:commands][:wget].should == { opts: "-a -b -c" }
101
+ config.to_h[:some][:deep][:indented][:config].should == "foo"
102
+ end
87
103
  end
88
104
 
105
+ end
106
+
107
+ describe "Hash conversion" do
108
+ it "properly convert into a Hash" do
109
+ outline = { a: 'a', b: 'b', some: { deep: { indented: { config: 'foo' } } } }.to_outline
110
+
111
+ outline.a.should == 'a'
112
+ outline.b.should == 'b'
113
+ outline.some.deep.indented.config.should == 'foo'
114
+ end
89
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000Z
12
+ date: 2012-04-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: meta_tools
16
- requirement: &70222087778620 !ruby/object:Gem::Requirement
16
+ requirement: &70269583507100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70222087778620
24
+ version_requirements: *70269583507100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70222087778140 !ruby/object:Gem::Requirement
27
+ requirement: &70269583506500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70222087778140
35
+ version_requirements: *70269583506500
36
36
  description: Easily set configurations on your Ruby apps.
37
37
  email: c00lryguy@gmail.com
38
38
  executables: []
@@ -41,10 +41,10 @@ extra_rdoc_files:
41
41
  - VERSION
42
42
  files:
43
43
  - VERSION
44
+ - Rakefile
44
45
  - Gemfile.lock
45
46
  - lib/outline.rb
46
47
  - spec/outline_spec.rb
47
- - spec/spec_helper.rb
48
48
  homepage: http://github.com/c00lryguy/outline
49
49
  licenses: []
50
50
  post_install_message:
@@ -57,12 +57,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
57
  - - ! '>='
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
+ segments:
61
+ - 0
62
+ hash: -3261779845905764895
60
63
  required_rubygems_version: !ruby/object:Gem::Requirement
61
64
  none: false
62
65
  requirements:
63
66
  - - ! '>='
64
67
  - !ruby/object:Gem::Version
65
68
  version: '0'
69
+ segments:
70
+ - 0
71
+ hash: -3261779845905764895
66
72
  requirements: []
67
73
  rubyforge_project:
68
74
  rubygems_version: 1.8.10
@@ -71,5 +77,3 @@ specification_version: 3
71
77
  summary: Simplify your configurations.
72
78
  test_files:
73
79
  - spec/outline_spec.rb
74
- - spec/spec_helper.rb
75
- has_rdoc:
@@ -1,3 +0,0 @@
1
- require 'outline'
2
-
3
- system('clear')