settings_js 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06892c399eb98cd3be8fa35110648df340ce8ce4
4
+ data.tar.gz: fa6f05a381ccc047a0e4840172e6a93ee2c9d737
5
+ SHA512:
6
+ metadata.gz: 256def4ff494af08edf60dd211c91aef121d9490bffa306579092a13370556375fced85087369998a181a21fdb684394456b79a08324065c27ea436870d9ef0a
7
+ data.tar.gz: 8c8fd7ab33f7edf22622775a315ecbe8d4c885b735b6c6d9c3d7423d8a6aade89df5e4fbcb2a395860c1360b2482175e31abe21715b95f0b6102789e78562e13
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  spec/javascripts/generated/
2
+ coverage
2
3
  Gemfile.lock
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ settings-js
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
6
+ - 2.0.0
4
7
  before_script:
5
8
  - 'export DISPLAY=:99.0'
6
9
  - 'sh -e /etc/init.d/xvfb start'
@@ -0,0 +1,33 @@
1
+ # 0.3.0 (no backward)
2
+
3
+ * Use base key as settings key
4
+
5
+ ```ruby
6
+ SettingsJs.configuration do |config|
7
+ config.keys = %w(adapters.maps)
8
+ end
9
+
10
+ # old Settings JS:
11
+ console.log(Settings);
12
+ # => { defaults: { latitude: 42.00, longitude: 41.00 }}
13
+
14
+ # current Settings JS:
15
+ console.log(Settings);
16
+ # => { maps: { defaults: { latitude: 42.00, longitude: 41.00 }}}
17
+ ```
18
+
19
+ # 0.2.0
20
+
21
+ * Make it a Rails engine
22
+
23
+ # 0.1.2
24
+
25
+ * Fix dependency error `active_support` -> `activesupport`
26
+
27
+ # 0.1.1
28
+
29
+ * Renaming adapters to backends
30
+
31
+ # 0.1.0
32
+
33
+ * Basic implementation with SettingsLogic backend
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
5
  group :test do
6
+ gem 'coveralls', require: false
6
7
  gem 'rake'
7
8
  end
data/README.markdown CHANGED
@@ -37,7 +37,7 @@ Load the Javascript file and access the `Settings` class:
37
37
  ```javascript
38
38
  // = require settings-js/settings
39
39
 
40
- Settings.host_name
40
+ Settings.hosts,host_name
41
41
  # => 'http://localhost:8080'
42
42
  ```
43
43
 
@@ -24,18 +24,18 @@ module SettingsJs
24
24
  # Examples
25
25
  #
26
26
  # Settingsjs::Backends::SettingsLogic.new(MySettings).to_hash('key1.subkey1_1')
27
- # # => 'Awesome value!'
27
+ # # => { subkey1_1: 'Awesome value!' }
28
28
  #
29
29
  # Returns the Hash value.
30
30
  def to_hash(base_key)
31
31
  keys = base_key.split(/\./)
32
+ hash_key = keys.last
32
33
  base_hash = klass.send(keys.shift)
33
34
 
34
35
  keys.each { |key| base_hash = base_hash.send(key) }
35
36
 
36
- base_hash
37
+ { hash_key => base_hash }
37
38
  end
38
-
39
39
  end
40
40
  end
41
41
  end
data/settings_js.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'settings_js'
3
- s.version = '0.2.0'
4
- s.date = '2013-02-13'
3
+ s.version = '0.3.0'
4
+ s.date = '2013-10-14'
5
5
  s.summary = 'Sharing same application settings between ruby and javascript'
6
6
  s.authors = ['Kevin Disneur']
7
7
  s.email = 'kevin.disneur@gmail.com'
@@ -1,10 +1,14 @@
1
1
  describe('Settings ', function() {
2
2
  it('Settings object contains a valid json', function() {
3
3
  expected_json = {
4
- sub_key1 : 'sub_value1',
5
- sub_key2_2_1 : 'sub_value2_2_1',
6
- sub_key2_2_2: {
7
- sub_key2_2_2_1: 'sub_value2_2_2_1'
4
+ key1 : {
5
+ sub_key1 : 'sub_value1',
6
+ },
7
+ sub_key2_2: {
8
+ sub_key2_2_1 : 'sub_value2_2_1',
9
+ sub_key2_2_2: {
10
+ sub_key2_2_2_1: 'sub_value2_2_2_1'
11
+ }
8
12
  }
9
13
  };
10
14
 
@@ -1,73 +1,8 @@
1
- # src_files
2
- #
3
- # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
- # Default: []
5
- #
6
- # EXAMPLE:
7
- #
8
- # src_files:
9
- # - lib/source1.js
10
- # - lib/source2.js
11
- # - dist/**/*.js
12
- #
13
1
  src_files:
14
- - spec/javascripts/generated/**/*.js.erb
15
-
16
- # stylesheets
17
- #
18
- # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
19
- # Default: []
20
- #
21
- # EXAMPLE:
22
- #
23
- # stylesheets:
24
- # - css/style.css
25
- # - stylesheets/*.css
26
- #
27
- stylesheets:
28
-
29
- # helpers
30
- #
31
- # Return an array of filepaths relative to spec_dir to include before jasmine specs.
32
- # Default: ["helpers/**/*.js"]
33
- #
34
- # EXAMPLE:
35
- #
36
- # helpers:
37
- # - helpers/**/*.js
38
- #
39
- helpers:
40
-
41
- # spec_files
42
- #
43
- # Return an array of filepaths relative to spec_dir to include.
44
- # Default: ["**/*[sS]pec.js"]
45
- #
46
- # EXAMPLE:
47
- #
48
- # spec_files:
49
- # - **/*[sS]pec.js
50
- #
51
- spec_files:
52
-
53
- # src_dir
54
- #
55
- # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
56
- # Default: project root
57
- #
58
- # EXAMPLE:
59
- #
60
- # src_dir: public
61
- #
62
- src_dir:
63
-
64
- # spec_dir
65
- #
66
- # Spec directory path. Your spec_files must be returned relative to this path.
67
- # Default: spec/javascripts
68
- #
69
- # EXAMPLE:
70
- #
71
- # spec_dir: spec/javascripts
72
- #
2
+ - 'spec/javascripts/generated/**/*.js.erb'
73
3
  spec_dir:
4
+ - 'spec/javascripts/settings-js'
5
+ spec_files:
6
+ - '**/*[sS]pec.js'
7
+ spec_helper:
8
+ - 'spec/javascripts/support/jasmine_helper.rb'
@@ -0,0 +1,41 @@
1
+ Spec_root = File.expand_path(File.join('..', '..', '..'), __FILE__)
2
+
3
+ $LOAD_PATH << File.join(Spec_root, '..', 'lib')
4
+ require 'settingslogic'
5
+ require 'settings_js'
6
+ require 'sprockets'
7
+
8
+ class DummySettings < Settingslogic
9
+ source File.join(Spec_root, 'fixtures', 'settings_js', 'backends', 'settings_logic.yml')
10
+ end
11
+
12
+ def gem_configuration
13
+ SettingsJs.configuration do |config|
14
+ config.backend = 'settings_logic'
15
+ config.keys = %w(key1 key2.sub_key2_2)
16
+ config.klass = DummySettings
17
+ end
18
+ end
19
+
20
+ def precompile_app_assets
21
+ puts 'Precompiling assets...'
22
+
23
+ generated_files_directory = File.expand_path(File.join('..', '..', 'generated'), __FILE__)
24
+
25
+ sprockets = Sprockets::Environment.new(File.join(Spec_root, '..', 'app', 'assets', 'javascripts'))
26
+ sprockets.append_path('settings-js')
27
+
28
+ assets = sprockets.find_asset('settings.js')
29
+ prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
30
+
31
+ FileUtils.mkpath(File.join(generated_files_directory))
32
+
33
+ assets.write_to(File.join(generated_files_directory, basename))
34
+ assets.to_a.each do |asset|
35
+ realname = asset.pathname.basename.to_s.split('.')[0..1].join('.')
36
+ assets.write_to(File.join(generated_files_directory, basename))
37
+ end
38
+ end
39
+
40
+ gem_configuration
41
+ precompile_app_assets
@@ -16,14 +16,16 @@ describe 'SettingsJs::Backends::SettingsLogic' do
16
16
 
17
17
  describe '#to_hash' do
18
18
  it 'returns subkeys when base key is in settings root' do
19
- backend_instance.to_hash('key1').should == { 'sub_key1' => 'sub_value1' }
19
+ backend_instance.to_hash('key1').should == { 'key1' => { 'sub_key1' => 'sub_value1' }}
20
20
  end
21
21
 
22
22
  it 'returns subkeys when base key is under the settings root' do
23
23
  expected_hash = {
24
- 'sub_key2_2_1' => 'sub_value2_2_1' ,
25
- 'sub_key2_2_2' => {
26
- 'sub_key2_2_2_1' => 'sub_value2_2_2_1'
24
+ 'sub_key2_2' => {
25
+ 'sub_key2_2_1' => 'sub_value2_2_1' ,
26
+ 'sub_key2_2_2' => {
27
+ 'sub_key2_2_2_1' => 'sub_value2_2_2_1'
28
+ }
27
29
  }
28
30
  }
29
31
 
@@ -5,33 +5,32 @@ describe SettingsJs::Merger do
5
5
  let(:merger) { SettingsJs::Merger.new }
6
6
 
7
7
  describe '#to_hash' do
8
-
9
8
  context 'when config.keys does not respond to "#reduce"' do
10
-
11
9
  it 'raises an TypeError' do
12
- SettingsJs.configuration { |config| config.keys = mock(:not_reduceable_object) }
10
+ SettingsJs.configuration { |config| config.keys = double(:not_reduceable_object) }
13
11
  expect { merger.to_hash }.to raise_error(TypeError)
14
12
  end
15
13
  end
16
14
 
17
15
  context 'when config.keys respond to "#reduce"' do
18
16
  let(:reduceable_object) do
19
- reduceable_object = mock(:reduceable_object)
17
+ reduceable_object = double(:reduceable_object)
20
18
  reduceable_object.stub(:reduce)
21
19
  reduceable_object
22
20
  end
23
21
 
24
22
  it 'does not raise a TypeError' do
25
23
  SettingsJs.configuration { |config| config.keys = reduceable_object }
26
- expect { merger.to_hash }.to_not raise_error(TypeError)
24
+ expect { merger.to_hash }.to_not raise_error
27
25
  end
28
26
  end
29
27
 
30
28
  it 'returns a hash which merge all keys hash response' do
31
- backend = mock(:backend)
32
- backend.stub(:to_hash).and_return({ key1: 'value1', key2: 'value2' }, { key2: { key2_1: 'value2_1', key2_2: 'value2_2' }})
29
+ backend = double(:backend)
30
+ backend.stub(:to_hash).with('key1').and_return({ key1: 'value1' })
31
+ backend.stub(:to_hash).with('key2').and_return({ key2: { key2_1: 'value2_1', key2_2: 'value2_2' }})
33
32
 
34
- config = mock(:config)
33
+ config = double(:config)
35
34
  config.stub(:keys).and_return(%w(key1 key2))
36
35
 
37
36
  merger.stub(:config).and_return(config)
@@ -51,11 +50,11 @@ describe SettingsJs::Merger do
51
50
 
52
51
  describe '#to_json' do
53
52
  it 'calls #to_json method on the #to_hash result' do
54
- hash_mocked = mock(:hash)
55
- hash_mocked.stub(:to_json)
56
- merger.stub(:to_hash).and_return(hash_mocked)
53
+ hash_doubleed = double(:hash)
54
+ hash_doubleed.stub(:to_json)
55
+ merger.stub(:to_hash).and_return(hash_doubleed)
57
56
 
58
- hash_mocked.should_receive(:to_json).once
57
+ hash_doubleed.should_receive(:to_json).once
59
58
 
60
59
  merger.to_json
61
60
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  Spec_root = File.expand_path('..', __FILE__)
2
5
 
3
6
  require File.join(Spec_root, '..', 'lib', 'settings_js')
metadata CHANGED
@@ -1,126 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settings_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kevin Disneur
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>'
17
+ - - '>'
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>'
24
+ - - '>'
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>'
31
+ - - '>'
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>'
38
+ - - '>'
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: sprockets
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: jasmine
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: settingslogic
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: shoulda
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description:
@@ -130,8 +115,10 @@ extensions: []
130
115
  extra_rdoc_files: []
131
116
  files:
132
117
  - .gitignore
133
- - .rvmrc
118
+ - .ruby-gemset
119
+ - .ruby-version
134
120
  - .travis.yml
121
+ - CHANGELOG.markdown
135
122
  - Gemfile
136
123
  - README.markdown
137
124
  - Rakefile
@@ -146,8 +133,8 @@ files:
146
133
  - spec/javascripts/helpers/SpecHelper.js
147
134
  - spec/javascripts/settings-js/settings_js_spec.js
148
135
  - spec/javascripts/support/jasmine.yml
149
- - spec/javascripts/support/jasmine_config.rb
150
- - spec/settings_js/backends/settings_js_spec.rb
136
+ - spec/javascripts/support/jasmine_helper.rb
137
+ - spec/settings_js/backends/settings_logic_spec.rb
151
138
  - spec/settings_js/config_spec.rb
152
139
  - spec/settings_js/merger_spec.rb
153
140
  - spec/settings_js_spec.rb
@@ -155,35 +142,34 @@ files:
155
142
  - spec/support/have_attr_accessor.rb
156
143
  homepage: http://rubygems.org/gems/settings_js
157
144
  licenses: []
145
+ metadata: {}
158
146
  post_install_message:
159
147
  rdoc_options: []
160
148
  require_paths:
161
149
  - lib
162
150
  required_ruby_version: !ruby/object:Gem::Requirement
163
- none: false
164
151
  requirements:
165
- - - ! '>='
152
+ - - '>='
166
153
  - !ruby/object:Gem::Version
167
154
  version: '0'
168
155
  required_rubygems_version: !ruby/object:Gem::Requirement
169
- none: false
170
156
  requirements:
171
- - - ! '>='
157
+ - - '>='
172
158
  - !ruby/object:Gem::Version
173
159
  version: '0'
174
160
  requirements: []
175
161
  rubyforge_project:
176
- rubygems_version: 1.8.24
162
+ rubygems_version: 2.0.6
177
163
  signing_key:
178
- specification_version: 3
164
+ specification_version: 4
179
165
  summary: Sharing same application settings between ruby and javascript
180
166
  test_files:
181
167
  - spec/fixtures/settings_js/backends/settings_logic.yml
182
168
  - spec/javascripts/helpers/SpecHelper.js
183
169
  - spec/javascripts/settings-js/settings_js_spec.js
184
170
  - spec/javascripts/support/jasmine.yml
185
- - spec/javascripts/support/jasmine_config.rb
186
- - spec/settings_js/backends/settings_js_spec.rb
171
+ - spec/javascripts/support/jasmine_helper.rb
172
+ - spec/settings_js/backends/settings_logic_spec.rb
187
173
  - spec/settings_js/config_spec.rb
188
174
  - spec/settings_js/merger_spec.rb
189
175
  - spec/settings_js_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm ruby-1.9.3-p327@settings-js --create
@@ -1,57 +0,0 @@
1
- Spec_root = File.expand_path(File.join('..', '..', '..'), __FILE__)
2
-
3
- $LOAD_PATH << File.join(Spec_root, '..', 'lib')
4
- require 'settingslogic'
5
- require 'settings_js'
6
- require 'sprockets'
7
-
8
- module Jasmine
9
-
10
- class DummySettings < Settingslogic
11
- source File.join(Spec_root, 'fixtures', 'settings_js', 'backends', 'settings_logic.yml')
12
- end
13
-
14
-
15
- class Config
16
-
17
- def js_files(spec_filter = nil)
18
- gem_configuration
19
-
20
- precompile_app_assets
21
-
22
- # this is code from the original jasmine config js_files method - you could also just alias_method_chain it
23
- spec_files_to_include = spec_filter.nil? ? spec_files : match_files(spec_dir, [spec_filter])
24
- src_files.collect { |f| '/' + f } + helpers.collect { |f| File.join(spec_path, f) } + spec_files_to_include.collect { |f| File.join(spec_path, f) }
25
- end
26
-
27
- private
28
-
29
- def gem_configuration
30
- SettingsJs.configuration do |config|
31
- config.backend = 'settings_logic'
32
- config.keys = %w(key1 key2.sub_key2_2)
33
- config.klass = DummySettings
34
- end
35
- end
36
-
37
- def precompile_app_assets
38
- puts 'Precompiling assets...'
39
-
40
- generated_files_directory = File.expand_path(File.join('..', '..', 'generated'), __FILE__)
41
-
42
- sprockets = Sprockets::Environment.new(File.join(Spec_root, '..', 'app', 'assets', 'javascripts'))
43
- sprockets.append_path('settings-js')
44
-
45
- assets = sprockets.find_asset('settings.js')
46
- prefix, basename = assets.pathname.to_s.split('/')[-2..-1]
47
-
48
- FileUtils.mkpath(File.join(generated_files_directory))
49
-
50
- assets.write_to(File.join(generated_files_directory, basename))
51
- assets.to_a.each do |asset|
52
- realname = asset.pathname.basename.to_s.split('.')[0..1].join('.')
53
- assets.write_to(File.join(generated_files_directory, basename))
54
- end
55
- end
56
- end
57
- end