settings_js 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,16 @@ module SettingsJs
8
8
  self.klass = klass
9
9
  end
10
10
 
11
+ # Public: Use application settings logic class to get values of a key.
12
+ #
13
+ # base_key - String formatted.
14
+ #
15
+ # Examples
16
+ #
17
+ # multiplex('Tom', 4)
18
+ # # => 'TomTomTomTom'
19
+ #
20
+ # Returns the duplicated String.
11
21
  def to_hash(base_key)
12
22
  keys = base_key.split(/\./)
13
23
  base_hash = klass.send(keys.shift)
@@ -4,6 +4,16 @@ require 'json'
4
4
  module SettingsJs
5
5
  class Merger
6
6
 
7
+ # Public: Get all values for keys defined in settins and merged it to a hash.
8
+ #
9
+ # Examples
10
+ #
11
+ # merger = SettingsJs::Merger.new
12
+ # merger.to_hash
13
+ # # => { key1: 'value', key2: { sub_key2: 'other value' }}
14
+ #
15
+ # Returns Hash.
16
+ # Raises TypeError if keys defined in config is not a reduceable object (Array,...)
7
17
  def to_hash
8
18
  unless config.keys.respond_to?(:reduce)
9
19
  raise TypeError.new('the configuration key "keys" must be reduceable')
@@ -12,6 +22,17 @@ module SettingsJs
12
22
  config.keys.reduce({}) { |hash, base_key| hash.merge(backend.to_hash(base_key)) }
13
23
  end
14
24
 
25
+ # Public: Get all values for keys defined in settins and merged it to a json.
26
+ #
27
+ # Examples
28
+ #
29
+ # merger = SettingsJs::Merger.new
30
+ # merger.to_hash
31
+ # # => { key1: 'value', key2: { sub_key2: 'other value' }}
32
+ # merger.to_json
33
+ # # => { 'key1': 'value', 'key2': { 'sub_key2': 'other value' }}
34
+ #
35
+ # Returns Json.
15
36
  def to_json
16
37
  to_hash.to_json
17
38
  end
data/lib/settings_js.rb CHANGED
@@ -3,6 +3,19 @@ require 'settings_js/merger'
3
3
 
4
4
  module SettingsJs
5
5
 
6
+ # Public: Configuration initializer.
7
+ #
8
+ # block - block with configuration object in parameter.
9
+ #
10
+ # Examples
11
+ #
12
+ # SettingsJs.condiguration do |config|
13
+ # config.backend = 'awesome_backend'
14
+ # config.klass = ApplicationSettings
15
+ # config.keys = %w(key.key2 key3)
16
+ # end
17
+ #
18
+ # Returns Nothing.
6
19
  def self.configuration(&block)
7
20
  block.call(SettingsJs::Config.instance)
8
21
  end
data/settings_js.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'settings_js'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.date = '2012-11-30'
5
5
  s.summary = 'Sharing same application settings between ruby and javascript'
6
6
  s.authors = ['Kevin Disneur']
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.test_files = `git ls-files -- spec/*`.split(/\n/)
10
10
  s.homepage = 'http://rubygems.org/gems/settings_js'
11
11
 
12
- s.add_dependency 'active_support', '> 1.0'
13
- s.add_dependency 'json', '> 0'
12
+ s.add_dependency 'activesupport', '> 0'
13
+ s.add_dependency 'json', '> 0'
14
14
  s.add_dependency 'sprockets'
15
15
 
16
16
  s.add_development_dependency 'jasmine'
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,13 +12,13 @@ cert_chain: []
12
12
  date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: active_support
15
+ name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>'
20
20
  - !ruby/object:Gem::Version
21
- version: '1.0'
21
+ version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>'
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: json
32
32
  requirement: !ruby/object:Gem::Requirement