client_data 0.0.1

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: 6bb6b81c32e608b723ee2763104f013db9bb1bfe
4
+ data.tar.gz: 452dda31bf1679f8da8f4218b23ba0fc8198f621
5
+ SHA512:
6
+ metadata.gz: 454bb6f0d613629a144a48991bef14417fb2f9af63b11c87933bc51e549c877274a07b769c6881e5ea41a2d82285a442158aff0e3fc76a015d2dc94d35395d29
7
+ data.tar.gz: 4e17553198a855b44e603d7134ce5c9f2098e07ee3bf5607369d16033c1a42944d15edd84f7d42f89f2aff015c671434d779c2a7cd2f3ef9b1a243505a7b6837
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://gems.cloudafrica.net'
2
+
3
+ # Specify your gem's dependencies in client_side.gemspec
4
+ gemspec
5
+
6
+ group :test, :development do
7
+ gem 'guard-rspec'
8
+ end
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: 'rspec -d .' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/hey_presto/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ClientData
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'client_data'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install client_data
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/client_data/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ module ClientData
2
+ module Adapters
3
+ class GonAdapter
4
+ def initialize(controller)
5
+ @controller = controller
6
+ end
7
+
8
+ def set(name, value)
9
+ @controller.gon.send("#{name}=", value)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module ClientData
2
+ module Adapters
3
+ def self.factory(controller)
4
+ provider = ClientData.configuration.provider
5
+ return provider unless provider.is_a?(Symbol) || provider.is_a?(String)
6
+ require "client_data/adapters/#{provider.downcase}_adapter"
7
+ "ClientData::Adapters::#{provider.to_s.capitalize}Adapter".constantize.new(controller)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module ClientData
2
+ class Builder
3
+ attr_accessor :controller
4
+
5
+ def initialize(controller)
6
+ @controller = controller
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ module ClientData
2
+ class Configuration
3
+ attr_accessor :builder_root, :provider, :builder_namespace
4
+
5
+ def initialize
6
+ default!
7
+ end
8
+
9
+ def default!
10
+ self.builder_root = nil
11
+ self.builder_namespace = ''
12
+ self.provider = :gon if defined?(Gon)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ module ClientData
2
+ module Methods
3
+ def self.included(klass)
4
+ klass.send(:before_filter, :client_data_filter) if klass.respond_to?(:before_filter)
5
+ klass.class_eval %(
6
+ class << self; attr_accessor :__cs_builders; end
7
+ )
8
+ klass.send(:include, InstanceMethods)
9
+ klass.send(:extend, ClassMethods)
10
+ end
11
+
12
+ module ClassMethods
13
+ def client_data(*configs)
14
+ self.__cs_builders ||= {}
15
+ self.__cs_builders[self.name] ||= []
16
+ self.__cs_builders[self.name].concat(configs)
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ def client_data_filter
22
+ configs = get_config_keys(params[:controller])
23
+ configs.each do |key|
24
+ begin
25
+ klass = "#{builder_namespace}#{key.to_s.capitalize}Builder"
26
+ klass = klass.constantize
27
+ rescue ::NameError => e
28
+ raise ClientData::Error, "Unable to find constant #{klass}, " \
29
+ "has ClientData.load_resources! been called? " \
30
+ "Error: #{e.message}"
31
+ end
32
+
33
+ data = build_data(klass)
34
+ provider.set(key, data)
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def build_data(klass)
41
+ arity = klass.instance_method(:initialize).arity
42
+ builder = arity == 0 ? klass.new : klass.new(self)
43
+ builder.build
44
+ end
45
+
46
+ def builder_namespace
47
+ ClientData.configuration.builder_namespace
48
+ end
49
+
50
+ def provider
51
+ @provider ||= Adapters.factory(self)
52
+ end
53
+
54
+ private
55
+
56
+ def get_config_keys(controller)
57
+ self.class.__cs_builders.try(:[], "#{controller.capitalize}Controller") || []
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails'
2
+
3
+ module Rails
4
+ module ClientData
5
+ class Railtie < ::Rails::Railtie
6
+ initializer :include_client_data do |app|
7
+ ActiveSupport.on_load(:action_controller) do
8
+ ActionController::Base.send(:include, ::HeyPresto::ClientData::Methods)
9
+ end
10
+
11
+ ::ClientData.configure do |c|
12
+ c.builder_root = "#{app.root}/app/js_builders"
13
+ end
14
+ end
15
+
16
+ config.after_initialize do
17
+ ::ClientData.load_builders!
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,3 @@
1
+ module ClientData
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'active_support/core_ext/hash'
2
+
3
+ require 'client_data/configuration'
4
+ require 'client_data/methods'
5
+ require 'client_data/builder'
6
+ require 'client_data/adapters'
7
+
8
+ require 'client_data/railtie' if defined?(Rails)
9
+
10
+ module ClientData
11
+ class Error < StandardError; end
12
+
13
+ @@configuration = nil
14
+
15
+ def self.configure
16
+ yield configuration
17
+ end
18
+
19
+ def self.configuration
20
+ @@configuration ||= Configuration.new
21
+ end
22
+
23
+ def self.load_builders!
24
+ raise Error, 'Client data builder_root is not set.' if configuration.builder_root.nil?
25
+
26
+ Dir[File.join(configuration.builder_root, '**/*_builder.rb')].each do |f|
27
+ load f
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: client_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stan Bondi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Use builder classes to build up data which JS can use.
56
+ email:
57
+ - stan@fixate.it
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - Guardfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/client_data.rb
68
+ - lib/client_data/adapters.rb
69
+ - lib/client_data/adapters/gon_adapter.rb
70
+ - lib/client_data/builder.rb
71
+ - lib/client_data/configuration.rb
72
+ - lib/client_data/methods.rb
73
+ - lib/client_data/railtie.rb
74
+ - lib/client_data/version.rb
75
+ homepage: https://github.com/fixate/client-data
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.0
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Use builder classes to build up data which JS can use.
99
+ test_files: []