settings_js 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  spec/javascripts/generated/
2
+ Gemfile.lock
data/README.markdown CHANGED
@@ -1,7 +1,8 @@
1
1
  # Welcome to Settings-js
2
2
 
3
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/kdisneur/settings-js)
4
- [![Travis CI](https://secure.travis-ci.org/kdisneur/settings-js.png)](http://travis-ci.org/kdisneur/settings-js)
3
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/fanaticio/settings-js)
4
+ [![Travis CI](https://secure.travis-ci.org/fanaticio/settings-js.png)](http://travis-ci.org/fanaticio/settings-js)
5
+ [![Dependency Status](https://gemnasium.com/fanaticio/settings-js.png)](https://gemnasium.com/fanaticio/settings-js)
5
6
 
6
7
  Use application specific settings with Javascript.
7
8
 
@@ -1,5 +1,14 @@
1
1
  module SettingsJs
2
2
  module Backends
3
+
4
+ # Public: SettingsLogic backend implementation to get values of Settings from string.
5
+ #
6
+ # klass - Class which is SettingsLogic in the application.
7
+ #
8
+ # Examples
9
+ #
10
+ # settingsjs_backend = Settings::Backends::SettingsLogic.new(MySettings)
11
+ #
3
12
  class SettingsLogic
4
13
 
5
14
  attr_accessor :klass
@@ -8,16 +17,16 @@ module SettingsJs
8
17
  self.klass = klass
9
18
  end
10
19
 
11
- # Public: Use application settings logic class to get values of a key.
20
+ # Public: Use application Settingslogic class to get values of a key.
12
21
  #
13
- # base_key - String formatted.
22
+ # base_key - String with path keys seperated by dots.
14
23
  #
15
24
  # Examples
16
25
  #
17
- # multiplex('Tom', 4)
18
- # # => 'TomTomTomTom'
26
+ # Settingsjs::Backends::SettingsLogic.new(MySettings).to_hash('key1.subkey1_1')
27
+ # # => 'Awesome value!'
19
28
  #
20
- # Returns the duplicated String.
29
+ # Returns the Hash value.
21
30
  def to_hash(base_key)
22
31
  keys = base_key.split(/\./)
23
32
  base_hash = klass.send(keys.shift)
@@ -0,0 +1,4 @@
1
+ module SettingsJS
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -2,9 +2,10 @@ require 'active_support/inflector'
2
2
  require 'json'
3
3
 
4
4
  module SettingsJs
5
+
5
6
  class Merger
6
7
 
7
- # Public: Get all values for keys defined in settins and merged it to a hash.
8
+ # Public: Get all values for keys defined in settings and merged it to a hash.
8
9
  #
9
10
  # Examples
10
11
  #
@@ -22,7 +23,7 @@ module SettingsJs
22
23
  config.keys.reduce({}) { |hash, base_key| hash.merge(backend.to_hash(base_key)) }
23
24
  end
24
25
 
25
- # Public: Get all values for keys defined in settins and merged it to a json.
26
+ # Public: Get all values for keys defined in settings and merged it to a json.
26
27
  #
27
28
  # Examples
28
29
  #
data/lib/settings_js.rb CHANGED
@@ -3,6 +3,10 @@ require 'settings_js/merger'
3
3
 
4
4
  module SettingsJs
5
5
 
6
+ if defined?(::Rails) && defined?(::Rails::Engine)
7
+ require 'settings_js/engine'
8
+ end
9
+
6
10
  # Public: Configuration initializer.
7
11
  #
8
12
  # block - block with configuration object in parameter.
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.1.2'
4
- s.date = '2012-11-30'
3
+ s.version = '0.2.0'
4
+ s.date = '2013-02-13'
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'
@@ -8,4 +8,32 @@ describe SettingsJs do
8
8
  end
9
9
  end
10
10
 
11
+ describe 'Engine' do
12
+ context 'when Rails constant does not exist' do
13
+ it 'does not make the gem an engine' do
14
+ reload_gem
15
+ defined?(::SettingsJS::Engine).should be_false
16
+ end
17
+ end
18
+
19
+ context 'when Rails constant exists' do
20
+ before(:each) { stub_const('Rails', Class.new) }
21
+
22
+ it 'does not make the gem an engine' do
23
+ reload_gem
24
+ defined?(::SettingsJS::Engine).should be_false
25
+ end
26
+
27
+ context 'when Rails::Engine constant exists' do
28
+ before(:each) { stub_const('Rails::Engine', Class.new) }
29
+
30
+ it 'makes the gem an engine' do
31
+ reload_gem
32
+ defined?(::SettingsJS::Engine).should be_true
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+
11
39
  end
data/spec/spec_helper.rb CHANGED
@@ -2,4 +2,9 @@ Spec_root = File.expand_path('..', __FILE__)
2
2
 
3
3
  require File.join(Spec_root, '..', 'lib', 'settings_js')
4
4
 
5
+ def reload_gem
6
+ load File.join(Spec_root, '..', 'lib', 'settings_js.rb')
7
+ end
8
+
5
9
  Dir[File.join(Spec_root, 'support', '**', '*.rb')].each { |support_helper| require support_helper }
10
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settings_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-30 00:00:00.000000000 Z
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -139,6 +139,7 @@ files:
139
139
  - lib/settings_js.rb
140
140
  - lib/settings_js/backends/settings_logic.rb
141
141
  - lib/settings_js/config.rb
142
+ - lib/settings_js/engine.rb
142
143
  - lib/settings_js/merger.rb
143
144
  - settings_js.gemspec
144
145
  - spec/fixtures/settings_js/backends/settings_logic.yml