json_config_attributes 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "activesupport"
9
+ gem "json"
10
+
11
+ group :development, :test do
12
+ gem "rspec", "~> 2.3.0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.6.4"
15
+ gem "rcov", ">= 0"
16
+ gem 'watchr'
17
+ gem 'fuubar'
18
+ gem 'spork'
19
+ gem 'activerecord'
20
+ end
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.1.0.rc4)
5
+ activesupport (= 3.1.0.rc4)
6
+ bcrypt-ruby (~> 2.1.4)
7
+ builder (~> 3.0.0)
8
+ i18n (~> 0.6)
9
+ activerecord (3.1.0.rc4)
10
+ activemodel (= 3.1.0.rc4)
11
+ activesupport (= 3.1.0.rc4)
12
+ arel (~> 2.1.1)
13
+ tzinfo (~> 0.3.27)
14
+ activesupport (3.1.0.rc4)
15
+ multi_json (~> 1.0)
16
+ arel (2.1.4)
17
+ bcrypt-ruby (2.1.4)
18
+ builder (3.0.0)
19
+ diff-lcs (1.1.2)
20
+ fuubar (0.0.5)
21
+ rspec (~> 2.0)
22
+ rspec-instafail (~> 0.1.4)
23
+ ruby-progressbar (~> 0.0.10)
24
+ git (1.2.5)
25
+ i18n (0.6.0)
26
+ jeweler (1.6.4)
27
+ bundler (~> 1.0)
28
+ git (>= 1.2.5)
29
+ rake
30
+ json (1.5.3)
31
+ multi_json (1.0.3)
32
+ rake (0.9.2)
33
+ rcov (0.9.10)
34
+ rspec (2.3.0)
35
+ rspec-core (~> 2.3.0)
36
+ rspec-expectations (~> 2.3.0)
37
+ rspec-mocks (~> 2.3.0)
38
+ rspec-core (2.3.1)
39
+ rspec-expectations (2.3.0)
40
+ diff-lcs (~> 1.1.2)
41
+ rspec-instafail (0.1.8)
42
+ rspec-mocks (2.3.0)
43
+ ruby-progressbar (0.0.10)
44
+ spork (0.8.4)
45
+ tzinfo (0.3.29)
46
+ watchr (0.7)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ activerecord
53
+ activesupport
54
+ bundler (~> 1.0.0)
55
+ fuubar
56
+ jeweler (~> 1.6.4)
57
+ json
58
+ rcov
59
+ rspec (~> 2.3.0)
60
+ spork
61
+ watchr
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 rangsikitpho
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # json_config_attributes
2
+
3
+ Simple ActiveSupport::Concern for converting a JSON config string into
4
+ methods available for read.
5
+
6
+ ## Install
7
+ gem 'json_config_attributes'
8
+ bundle
9
+
10
+ ## Usage
11
+
12
+ ```ruby
13
+ class Activity < ActiveRecord::Base
14
+ include JsonConfigAttributes
15
+ json_config_attributes :config_json,
16
+ :name
17
+ end
18
+
19
+ # name is now available as an accessor
20
+ a = Activity.new(:config_json => '{ "name" : "activity name" }'
21
+ a.config_json
22
+ => "activity name"
23
+ ````
24
+
25
+ ## TODO
26
+ Add write support to update config json by modifying attributes directly.
27
+
28
+ Possibly memoize parsed JSON.
29
+
30
+ ## Contributing to json_config_attributes
31
+
32
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
33
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
34
+ * Fork the project
35
+ * Start a feature/bugfix branch
36
+ * Commit and push until you are happy with your contribution
37
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
+
40
+ ## Copyright
41
+
42
+ Copyright (c) 2011 Joshua Rangsikitpho, SocialVibe. See LICENSE.txt for
43
+ further details.
44
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "json_config_attributes"
18
+ gem.homepage = "http://github.com/rangsikitpho/json_config_attributes"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{JSON config attribute helper}
21
+ gem.description = %Q{Simple ActiveSupport::Concern for converting a JSON config string into methods available for read.}
22
+ gem.email = "rangsikitpho@gmail.com"
23
+ gem.authors = ["rangsikitpho"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "json_config_attributes #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{json_config_attributes}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["rangsikitpho"]
12
+ s.date = %q{2011-08-12}
13
+ s.description = %q{Simple ActiveSupport::Concern for converting a JSON config string into methods available for read.}
14
+ s.email = %q{rangsikitpho@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "json_config_attributes.gemspec",
29
+ "lib/json_config_attributes.rb",
30
+ "spec/json_config_attributes_spec.rb",
31
+ "spec/spec_helper.rb",
32
+ "watchr.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/rangsikitpho/json_config_attributes}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.4.2}
38
+ s.summary = %q{JSON config attribute helper}
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
45
+ s.add_runtime_dependency(%q<json>, [">= 0"])
46
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ s.add_development_dependency(%q<watchr>, [">= 0"])
51
+ s.add_development_dependency(%q<fuubar>, [">= 0"])
52
+ s.add_development_dependency(%q<spork>, [">= 0"])
53
+ s.add_development_dependency(%q<activerecord>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<activesupport>, [">= 0"])
56
+ s.add_dependency(%q<json>, [">= 0"])
57
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ s.add_dependency(%q<watchr>, [">= 0"])
62
+ s.add_dependency(%q<fuubar>, [">= 0"])
63
+ s.add_dependency(%q<spork>, [">= 0"])
64
+ s.add_dependency(%q<activerecord>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<activesupport>, [">= 0"])
68
+ s.add_dependency(%q<json>, [">= 0"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
72
+ s.add_dependency(%q<rcov>, [">= 0"])
73
+ s.add_dependency(%q<watchr>, [">= 0"])
74
+ s.add_dependency(%q<fuubar>, [">= 0"])
75
+ s.add_dependency(%q<spork>, [">= 0"])
76
+ s.add_dependency(%q<activerecord>, [">= 0"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,21 @@
1
+ require 'active_support'
2
+ require 'json'
3
+ module JsonConfigAttributes
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def json_config_attributes(json, *attribute_names)
8
+ attribute_names.each do |attribute_name|
9
+ class_eval <<-RUBY
10
+ def #{attribute_name}
11
+ config_hash = JSON.parse #{json}
12
+ config_hash['#{attribute_name}']
13
+ rescue
14
+ nil
15
+ end
16
+ RUBY
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "JsonConfigAttributes" do
4
+ before(:each) do
5
+ class Activity
6
+ include JsonConfigAttributes
7
+ attr_accessor :config_json
8
+ #'{ "name" : "awesome activity" }'
9
+ def initialize(config_json='')
10
+ self.config_json = config_json
11
+ end
12
+ end
13
+ end
14
+
15
+ after(:each) do
16
+ Object.send(:remove_const, :Activity)
17
+ end
18
+
19
+ it "makes the json_config_attributes method available" do
20
+ Activity.should respond_to :json_config_attributes
21
+ end
22
+
23
+ it "should return the json value properly" do
24
+ class Activity
25
+ json_config_attributes :config_json, :name
26
+ end
27
+
28
+ a = Activity.new('{ "name" : "awesome activity" }')
29
+
30
+ a.name.should == "awesome activity"
31
+ end
32
+
33
+ it "should return nil for a json attribute that isn't referenced in the config" do
34
+ class Activity
35
+ json_config_attributes :config_json, :unknown
36
+ end
37
+
38
+ a = Activity.new
39
+ a.unknown.should be_nil
40
+ end
41
+
42
+ it "should raise an error if an attribute name that isn't specified is used and not defined by the class" do
43
+ class Activity
44
+ json_config_attributes :config_json, :name
45
+ end
46
+
47
+ a = Activity.new
48
+ lambda { a.unknown }.should raise_error(NoMethodError)
49
+ end
50
+
51
+ end
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+ Spork.prefork do
5
+ # Loading more in this block will cause your tests to run faster. However,
6
+ # if you change any configuration or code from libraries loaded here, you'll
7
+ # need to restart spork for it take effect.
8
+
9
+ end
10
+
11
+ Spork.each_run do
12
+ # This code will be run each time you run your specs.
13
+
14
+ end
15
+
16
+ # --- Instructions ---
17
+ # - Sort through your spec_helper file. Place as much environment loading
18
+ # code that you don't normally modify during development in the
19
+ # Spork.prefork block.
20
+ # - Place the rest under Spork.each_run block
21
+ # - Any code that is left outside of the blocks will be ran during preforking
22
+ # and during each_run!
23
+ # - These instructions should self-destruct in 10 seconds. If they don't,
24
+ # feel free to delete them.
25
+ #
26
+
27
+
28
+
29
+
30
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
31
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
32
+ require 'rspec'
33
+ require 'json_config_attributes'
34
+
35
+ # Requires supporting files with custom matchers and macros, etc,
36
+ # in ./support/ and its subdirectories.
37
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
38
+
39
+ RSpec.configure do |config|
40
+
41
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env watchr
2
+
3
+ def run(cmd)
4
+ full_command = "bundle exec rspec #{cmd}"
5
+ puts(full_command)
6
+ system(full_command)
7
+ end
8
+
9
+ def run_all
10
+ run("spec")
11
+ end
12
+
13
+ watch( '^lib/(.*)\.rb' ) { |m| run("spec/%s_spec.rb" % m[1]) }
14
+ watch( '^spec/spec_helper\.rb' ) { run_all }
15
+ watch( '^spec.*/.*_spec\.rb' ) { |m| run(m[0]) }
16
+
17
+ puts "watchr ready"
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_config_attributes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - rangsikitpho
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-12 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: activesupport
24
+ type: :runtime
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: json
38
+ type: :runtime
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ name: rspec
52
+ type: :development
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 2
61
+ - 3
62
+ - 0
63
+ version: 2.3.0
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ prerelease: false
67
+ name: bundler
68
+ type: :development
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 23
75
+ segments:
76
+ - 1
77
+ - 0
78
+ - 0
79
+ version: 1.0.0
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ prerelease: false
83
+ name: jeweler
84
+ type: :development
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 7
91
+ segments:
92
+ - 1
93
+ - 6
94
+ - 4
95
+ version: 1.6.4
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ name: rcov
100
+ type: :development
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirement: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ name: watchr
114
+ type: :development
115
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirement: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ prerelease: false
127
+ name: fuubar
128
+ type: :development
129
+ version_requirements: &id008 !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirement: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ prerelease: false
141
+ name: spork
142
+ type: :development
143
+ version_requirements: &id009 !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ requirement: *id009
153
+ - !ruby/object:Gem::Dependency
154
+ prerelease: false
155
+ name: activerecord
156
+ type: :development
157
+ version_requirements: &id010 !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ hash: 3
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ requirement: *id010
167
+ description: Simple ActiveSupport::Concern for converting a JSON config string into methods available for read.
168
+ email: rangsikitpho@gmail.com
169
+ executables: []
170
+
171
+ extensions: []
172
+
173
+ extra_rdoc_files:
174
+ - LICENSE.txt
175
+ - README.md
176
+ files:
177
+ - .document
178
+ - .rspec
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - VERSION
185
+ - json_config_attributes.gemspec
186
+ - lib/json_config_attributes.rb
187
+ - spec/json_config_attributes_spec.rb
188
+ - spec/spec_helper.rb
189
+ - watchr.rb
190
+ has_rdoc: true
191
+ homepage: http://github.com/rangsikitpho/json_config_attributes
192
+ licenses:
193
+ - MIT
194
+ post_install_message:
195
+ rdoc_options: []
196
+
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ none: false
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ hash: 3
205
+ segments:
206
+ - 0
207
+ version: "0"
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ hash: 3
214
+ segments:
215
+ - 0
216
+ version: "0"
217
+ requirements: []
218
+
219
+ rubyforge_project:
220
+ rubygems_version: 1.4.2
221
+ signing_key:
222
+ specification_version: 3
223
+ summary: JSON config attribute helper
224
+ test_files: []
225
+