yacht 0.2.6 → 0.2.7
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.
- data/HISTORY.md +27 -0
- data/README.rdoc +11 -5
- data/lib/yacht/base.rb +1 -1
- data/lib/yacht/classy_struct.rb +1 -1
- data/lib/yacht/hash_helper.rb +23 -0
- data/lib/yacht/javascript.rb +2 -1
- data/lib/yacht/loader.rb +5 -3
- data/lib/yacht/rails.rb +3 -1
- data/lib/yacht/version.rb +2 -2
- data/lib/yacht.rb +1 -1
- data/spec/spec_helper.rb +8 -6
- data/spec/yacht/rails_spec.rb +0 -5
- metadata +49 -7
- data/lib/monkeypatches/hash.rb +0 -24
data/HISTORY.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## [0.2.6](https://github.com/attinteractive/yacht/compare/0.2.5...0.2.6)
|
2
|
+
|
3
|
+
### Bugfixes
|
4
|
+
* Making it possible to have any environment without having a configuration ([#13](https://github.com/attinteractive/yacht/pull/13) Alf Mikula)
|
5
|
+
* Correct docs
|
6
|
+
* Update cucumber version in development dependencies
|
7
|
+
* Clean up documentation
|
8
|
+
* Clean up cucumber features
|
9
|
+
|
10
|
+
|
11
|
+
## [0.2.5](https://github.com/attinteractive/yacht/compare/0.2.0...0.2.5)
|
12
|
+
|
13
|
+
### Bugfixes
|
14
|
+
* Fix bug with default value for Yacht::Loader.dir by forcing manual setting of dir outside of rails
|
15
|
+
|
16
|
+
### New Features
|
17
|
+
* Add feature that allows export to javascript ([#2](https://github.com/attinteractive/yacht/issues/2) Mani Tadayon)
|
18
|
+
* Add :rails_env key when Rails is defined
|
19
|
+
|
20
|
+
|
21
|
+
## [0.2.0](https://github.com/attinteractive/yacht/compare/0.1.2...0.2.0)
|
22
|
+
|
23
|
+
### New Features
|
24
|
+
* Use Yacht for name of class instead of YachtLoader
|
25
|
+
([#1](https://github.com/attinteractive/yacht/issues/1) Mani Tadayon)
|
26
|
+
* Add Cucumber features
|
27
|
+
* Simplify RSpec examples covered by new cucumber features
|
data/README.rdoc
CHANGED
@@ -58,12 +58,14 @@ First create one or more of the following YAML files in the same directory to de
|
|
58
58
|
production:
|
59
59
|
cdn_host: localhost
|
60
60
|
|
61
|
-
=== Step 2: Use Yacht.my_key or Yacht['my_key'] in ruby
|
61
|
+
=== Step 2: Use +Yacht.my_key+ or <tt>Yacht['my_key']</tt> in ruby
|
62
62
|
|
63
63
|
* <b>Rails</b>:
|
64
64
|
# now you can access any key set in your YAML files with:
|
65
65
|
Yacht.my_key
|
66
66
|
# => "my_value"
|
67
|
+
Yacht['my_key']
|
68
|
+
# => "my_value"
|
67
69
|
|
68
70
|
* Outside of rails, you need to tell +Yacht+ where your YAML files are stored, and what environment you want to use.
|
69
71
|
Yacht::Loader.dir = '/path/to/YAML/dir'
|
@@ -73,7 +75,7 @@ First create one or more of the following YAML files in the same directory to de
|
|
73
75
|
|
74
76
|
== Other features
|
75
77
|
|
76
|
-
=== Yacht::Loader.to_js_snippet export to javascript
|
78
|
+
=== <tt>Yacht::Loader.to_js_snippet</tt> export to javascript
|
77
79
|
If you would like to access values stored in Yacht inside of javascript, there is a helper for that. First, create a YAML file to tell Yacht which keys should be exported:
|
78
80
|
|
79
81
|
# config/yacht/base_keys.yml
|
@@ -81,7 +83,7 @@ If you would like to access values stored in Yacht inside of javascript, there i
|
|
81
83
|
# remember that any values exported to javascript will be visible to all visitors to your site
|
82
84
|
- cookie_domain
|
83
85
|
|
84
|
-
Then use Yacht::Loader#to_js_snippet to create a string that can be eval'd or included in the DOM:
|
86
|
+
Then use +Yacht::Loader#to_js_snippet+ to create a string that can be eval'd or included in the DOM:
|
85
87
|
|
86
88
|
Yacht::Loader.to_js_snippet
|
87
89
|
# => ";var Yacht = {\"cookie_domain\":\"example.com\"};"
|
@@ -92,9 +94,9 @@ You can also add in extra values from outside of Yacht using the :merge option,
|
|
92
94
|
# => ";var Yacht = {\"cookie_domain\":\"example.com\",\"current_time\":\"06/29/2011\"};"
|
93
95
|
|
94
96
|
|
95
|
-
=== yacht_js_snippet Rails helper
|
97
|
+
=== +yacht_js_snippet+ Rails helper
|
96
98
|
|
97
|
-
When using Yacht inside of a Rails application, you can use the yacht_js_snippet method to wrap the string from Yacht::Loader#to_js_snippet in a script tag using Rails' javascript_tag helper.
|
99
|
+
When using Yacht inside of a Rails application, you can use the +yacht_js_snippet+ method to wrap the string from +Yacht::Loader#to_js_snippet+ in a script tag using Rails' +javascript_tag+ helper.
|
98
100
|
|
99
101
|
Yacht.rails_env
|
100
102
|
# => "development" # Yacht automatically adds the current Rails environment in ruby
|
@@ -109,6 +111,10 @@ When using Yacht inside of a Rails application, you can use the yacht_js_snippet
|
|
109
111
|
# => "<script type=\"text/javascript\">\n//<![CDATA[\n;var Yacht = {\"cookie_domain\":\"localhost\",\"rails_env\":\"development\",\"current_time\":\"06/29/2011\"};\n//]]>\n</script>"
|
110
112
|
|
111
113
|
|
114
|
+
== Ruby compatibility
|
115
|
+
|
116
|
+
Yacht works with ruby 1.8.7 and 1.9.2.
|
117
|
+
|
112
118
|
== License
|
113
119
|
|
114
120
|
Yacht is licensed under the MIT License with one addition: The Software shall be used for Good, not Evil.
|
data/lib/yacht/base.rb
CHANGED
data/lib/yacht/classy_struct.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Yacht::HashHelper
|
2
|
+
# adapted from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
3
|
+
# Returns a new hash with +some_hash+ and +other_hash+ merged recursively.
|
4
|
+
# Equivalent to some_hash.deep_merge(other_hash) in Rails
|
5
|
+
def deep_merge(some_hash, other_hash)
|
6
|
+
some_hash.merge(other_hash) do |key, oldval, newval|
|
7
|
+
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
8
|
+
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
9
|
+
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? deep_merge(oldval, newval) : newval
|
10
|
+
end
|
11
|
+
end
|
12
|
+
module_function :deep_merge
|
13
|
+
|
14
|
+
# adapted from http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Slice.html
|
15
|
+
# Returns a new hash with only the given keys
|
16
|
+
def slice(some_hash, *keys)
|
17
|
+
allowed = Set.new(keys)
|
18
|
+
hash = {}
|
19
|
+
allowed.each { |k| hash[k] = some_hash[k] if some_hash.has_key?(k) }
|
20
|
+
hash
|
21
|
+
end
|
22
|
+
module_function :slice
|
23
|
+
end
|
data/lib/yacht/javascript.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "yacht/hash_helper"
|
1
2
|
require 'json'
|
2
3
|
|
3
4
|
class Yacht::Loader
|
@@ -8,7 +9,7 @@ class Yacht::Loader
|
|
8
9
|
# @option opts [Hash] :merge ({}) hash to be merged into to_hash
|
9
10
|
def to_js_snippet(opts={})
|
10
11
|
hash_to_merge = opts.delete(:merge) || {}
|
11
|
-
hash = to_hash(opts)
|
12
|
+
hash = Yacht::HashHelper.slice(to_hash(opts), *js_keys).merge(hash_to_merge)
|
12
13
|
";var Yacht = #{hash.to_json};"
|
13
14
|
end
|
14
15
|
|
data/lib/yacht/loader.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "yacht/hash_helper"
|
2
|
+
|
1
3
|
class Yacht::Loader
|
2
4
|
class << self
|
3
5
|
def environment
|
@@ -26,7 +28,7 @@ class Yacht::Loader
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def all
|
29
|
-
chain_configs(base_config, self.environment)
|
31
|
+
Yacht::HashHelper.deep_merge( chain_configs(base_config, self.environment), local_config )
|
30
32
|
end
|
31
33
|
|
32
34
|
# @param [Hash] opts the options for creating the hash
|
@@ -37,7 +39,7 @@ class Yacht::Loader
|
|
37
39
|
self.environment = opts[:env] if opts.has_key?(:env)
|
38
40
|
|
39
41
|
if opts[:apply_whitelist?]
|
40
|
-
|
42
|
+
Yacht::HashHelper.slice(all, *whitelist)
|
41
43
|
else
|
42
44
|
all
|
43
45
|
end
|
@@ -93,7 +95,7 @@ class Yacht::Loader
|
|
93
95
|
config['default'] || {}
|
94
96
|
end
|
95
97
|
|
96
|
-
|
98
|
+
Yacht::HashHelper.deep_merge(parent, config[env])
|
97
99
|
else
|
98
100
|
config['default'] || {}
|
99
101
|
end
|
data/lib/yacht/rails.rb
CHANGED
@@ -17,7 +17,9 @@ class Yacht::Loader
|
|
17
17
|
def all_with_rails_env
|
18
18
|
all_without_rails_env.merge('rails_env' => Rails.env)
|
19
19
|
end
|
20
|
-
alias_method_chain
|
20
|
+
# alias_method_chain is wonky in rspec with ruby 1.8.7
|
21
|
+
alias_method :all_without_rails_env, :all
|
22
|
+
alias_method :all, :all_with_rails_env
|
21
23
|
|
22
24
|
end
|
23
25
|
end
|
data/lib/yacht/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Yacht
|
2
|
-
VERSION = "0.2.
|
1
|
+
class Yacht
|
2
|
+
VERSION = "0.2.7"
|
3
3
|
end
|
data/lib/yacht.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,15 +5,17 @@ require 'rubygems'
|
|
5
5
|
require 'bundler'
|
6
6
|
Bundler.setup
|
7
7
|
|
8
|
-
# ==============
|
9
|
-
# = SimpleCov! =
|
10
|
-
# ==============
|
11
|
-
require 'simplecov'
|
12
|
-
SimpleCov.start
|
13
|
-
|
14
8
|
require 'yacht'
|
15
9
|
|
16
10
|
RSpec.configure do |config|
|
11
|
+
config.before :all do
|
12
|
+
# ==============
|
13
|
+
# = SimpleCov! =
|
14
|
+
# ==============
|
15
|
+
require 'simplecov'
|
16
|
+
SimpleCov.start
|
17
|
+
end
|
18
|
+
|
17
19
|
config.after :each do
|
18
20
|
Yacht::Loader.environment = nil
|
19
21
|
Yacht::Loader.dir = nil
|
data/spec/yacht/rails_spec.rb
CHANGED
@@ -43,10 +43,5 @@ describe "Rails support" do
|
|
43
43
|
Rails.stub(:env).and_return(:awesome)
|
44
44
|
subject.all_with_rails_env.should == {:foo => :bar, 'rails_env' => :awesome}
|
45
45
|
end
|
46
|
-
|
47
|
-
it "aliases all to all_without_rails_env" do
|
48
|
-
Object.should_receive(:alias_method_chain).with(:all, :rails_env)
|
49
|
-
load "yacht/rails.rb"
|
50
|
-
end
|
51
46
|
end
|
52
47
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yacht
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 7
|
10
|
+
version: 0.2.7
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Mani Tadayon
|
@@ -11,8 +16,7 @@ autorequire:
|
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
18
|
|
14
|
-
date: 2011-07-
|
15
|
-
default_executable:
|
19
|
+
date: 2011-07-27 00:00:00 Z
|
16
20
|
dependencies:
|
17
21
|
- !ruby/object:Gem::Dependency
|
18
22
|
name: classy_struct
|
@@ -22,6 +26,11 @@ dependencies:
|
|
22
26
|
requirements:
|
23
27
|
- - ">="
|
24
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
- 2
|
25
34
|
version: 0.3.2
|
26
35
|
type: :runtime
|
27
36
|
version_requirements: *id001
|
@@ -33,6 +42,9 @@ dependencies:
|
|
33
42
|
requirements:
|
34
43
|
- - ">="
|
35
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
36
48
|
version: "0"
|
37
49
|
type: :runtime
|
38
50
|
version_requirements: *id002
|
@@ -44,6 +56,11 @@ dependencies:
|
|
44
56
|
requirements:
|
45
57
|
- - ">="
|
46
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 31
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 4
|
63
|
+
- 0
|
47
64
|
version: 2.4.0
|
48
65
|
type: :development
|
49
66
|
version_requirements: *id003
|
@@ -55,6 +72,10 @@ dependencies:
|
|
55
72
|
requirements:
|
56
73
|
- - ~>
|
57
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 15
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 0
|
58
79
|
version: "1.0"
|
59
80
|
type: :development
|
60
81
|
version_requirements: *id004
|
@@ -66,6 +87,9 @@ dependencies:
|
|
66
87
|
requirements:
|
67
88
|
- - ">="
|
68
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
69
93
|
version: "0"
|
70
94
|
type: :development
|
71
95
|
version_requirements: *id005
|
@@ -77,6 +101,11 @@ dependencies:
|
|
77
101
|
requirements:
|
78
102
|
- - ">="
|
79
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 23
|
105
|
+
segments:
|
106
|
+
- 2
|
107
|
+
- 6
|
108
|
+
- 0
|
80
109
|
version: 2.6.0
|
81
110
|
type: :development
|
82
111
|
version_requirements: *id006
|
@@ -88,6 +117,11 @@ dependencies:
|
|
88
117
|
requirements:
|
89
118
|
- - ">="
|
90
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 13
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
- 4
|
124
|
+
- 1
|
91
125
|
version: 0.4.1
|
92
126
|
type: :development
|
93
127
|
version_requirements: *id007
|
@@ -108,6 +142,7 @@ files:
|
|
108
142
|
- .rvmrc
|
109
143
|
- .yardopts
|
110
144
|
- Gemfile
|
145
|
+
- HISTORY.md
|
111
146
|
- LICENSE
|
112
147
|
- README.rdoc
|
113
148
|
- Rakefile
|
@@ -122,11 +157,11 @@ files:
|
|
122
157
|
- features/support/env.rb
|
123
158
|
- gem_tasks/cucumber.rake
|
124
159
|
- gem_tasks/spec.rake
|
125
|
-
- lib/monkeypatches/hash.rb
|
126
160
|
- lib/monkeypatches/rails_helper.rb
|
127
161
|
- lib/yacht.rb
|
128
162
|
- lib/yacht/base.rb
|
129
163
|
- lib/yacht/classy_struct.rb
|
164
|
+
- lib/yacht/hash_helper.rb
|
130
165
|
- lib/yacht/javascript.rb
|
131
166
|
- lib/yacht/loader.rb
|
132
167
|
- lib/yacht/rails.rb
|
@@ -139,7 +174,6 @@ files:
|
|
139
174
|
- spec/yacht/loader_spec.rb
|
140
175
|
- spec/yacht/rails_spec.rb
|
141
176
|
- yacht.gemspec
|
142
|
-
has_rdoc: true
|
143
177
|
homepage: https://github.com/attinteractive/yacht
|
144
178
|
licenses: []
|
145
179
|
|
@@ -153,20 +187,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
187
|
requirements:
|
154
188
|
- - ">="
|
155
189
|
- !ruby/object:Gem::Version
|
190
|
+
hash: 3
|
191
|
+
segments:
|
192
|
+
- 0
|
156
193
|
version: "0"
|
157
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
195
|
none: false
|
159
196
|
requirements:
|
160
197
|
- - ">="
|
161
198
|
- !ruby/object:Gem::Version
|
199
|
+
hash: 21
|
200
|
+
segments:
|
201
|
+
- 1
|
202
|
+
- 3
|
203
|
+
- 7
|
162
204
|
version: 1.3.7
|
163
205
|
requirements: []
|
164
206
|
|
165
207
|
rubyforge_project:
|
166
|
-
rubygems_version: 1.
|
208
|
+
rubygems_version: 1.8.6
|
167
209
|
signing_key:
|
168
210
|
specification_version: 3
|
169
|
-
summary: yacht-0.2.
|
211
|
+
summary: yacht-0.2.7
|
170
212
|
test_files:
|
171
213
|
- spec/monkeypatches/rails_helper_spec.rb
|
172
214
|
- spec/spec_helper.rb
|
data/lib/monkeypatches/hash.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
if !Hash.instance_methods.include?(:deep_merge)
|
2
|
-
class Hash
|
3
|
-
# copied from ActiveSupport::CoreExtensions::Hash::DeepMerge 2.3.8
|
4
|
-
def deep_merge(other_hash)
|
5
|
-
self.merge(other_hash) do |key, oldval, newval|
|
6
|
-
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
7
|
-
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
8
|
-
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
if !Hash.instance_methods.include?(:slice)
|
15
|
-
class Hash
|
16
|
-
# copied from http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Slice.html
|
17
|
-
def slice(*keys)
|
18
|
-
allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
|
19
|
-
hash = {}
|
20
|
-
allowed.each { |k| hash[k] = self[k] if has_key?(k) }
|
21
|
-
hash
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|