concern_builder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +22 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/concern_builder.gemspec +27 -0
- data/lib/concern_builder/options_parser.rb +9 -0
- data/lib/concern_builder/version.rb +3 -0
- data/lib/concern_builder.rb +47 -0
- data/spec/lib/concern_builder_spec.rb +46 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/fixture_helpers.rb +19 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 32ecb03d856f4c42235d69b1f02a6e62f2b2fae9
|
4
|
+
data.tar.gz: f243d1bc41f327a0b7306b6691bea86b153d73ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84739e990853087684920296a616b695e55b2608ad775bf57730cc7bf2f1364f51586d9428ef9f04d83799747029f35f1c4534413c114adcdb14b9c77899bed6
|
7
|
+
data.tar.gz: cf1390c2d25a84dcff9ff548b1296de5b18eaa83842eae33227c5d50a720df0a5065e2badda0f2b7cde323a534869cc8df8731f5c3e4c2fe2819a266da294818
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
concern_builder (0.0.1)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.2.3)
|
11
|
+
i18n (~> 0.7)
|
12
|
+
json (~> 1.7, >= 1.7.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
diff-lcs (1.2.5)
|
17
|
+
docile (1.1.5)
|
18
|
+
i18n (0.7.0)
|
19
|
+
json (1.8.3)
|
20
|
+
minitest (5.7.0)
|
21
|
+
rake (10.4.2)
|
22
|
+
rspec (2.99.0)
|
23
|
+
rspec-core (~> 2.99.0)
|
24
|
+
rspec-expectations (~> 2.99.0)
|
25
|
+
rspec-mocks (~> 2.99.0)
|
26
|
+
rspec-core (2.99.2)
|
27
|
+
rspec-expectations (2.99.2)
|
28
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
29
|
+
rspec-mocks (2.99.4)
|
30
|
+
simplecov (0.10.0)
|
31
|
+
docile (~> 1.1.0)
|
32
|
+
json (~> 1.8)
|
33
|
+
simplecov-html (~> 0.10.0)
|
34
|
+
simplecov-html (0.10.0)
|
35
|
+
thread_safe (0.3.5)
|
36
|
+
tzinfo (1.2.2)
|
37
|
+
thread_safe (~> 0.1)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.6)
|
44
|
+
concern_builder!
|
45
|
+
rake
|
46
|
+
rspec (~> 2.14)
|
47
|
+
simplecov
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Bidu Corretora
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'concern_builder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'concern_builder'
|
8
|
+
gem.version = ConcernBuilder::VERSION
|
9
|
+
gem.authors = ["DarthJee"]
|
10
|
+
gem.email = ["darthjee@gmail.com"]
|
11
|
+
gem.homepage = 'https://github.com/darthjee/concern_builder'
|
12
|
+
gem.description = 'Gem for easy concern creation'
|
13
|
+
gem.summary = gem.description
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'activesupport'
|
21
|
+
|
22
|
+
gem.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "rspec", "~> 2.14"
|
25
|
+
gem.add_development_dependency 'simplecov'
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
class ConcernBuilder
|
5
|
+
require 'concern_builder/version'
|
6
|
+
require 'concern_builder/options_parser'
|
7
|
+
|
8
|
+
include OptionsParser
|
9
|
+
|
10
|
+
attr_reader :attr_names, :methods_def
|
11
|
+
|
12
|
+
def initialize(attr_names, instance, options)
|
13
|
+
@attr_names = attr_names
|
14
|
+
@instance = instance
|
15
|
+
@options = options
|
16
|
+
@methods_def = []
|
17
|
+
init
|
18
|
+
end
|
19
|
+
|
20
|
+
def build
|
21
|
+
methods_def.each do |method_def|
|
22
|
+
@instance.module_eval(method_def, __FILE__, __LINE__ + 1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def add_method(name, code = nil, &block)
|
29
|
+
if code.is_a?(String)
|
30
|
+
add_code_method(name, code)
|
31
|
+
else
|
32
|
+
add_block_method(name, block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_block_method(name, block)
|
37
|
+
@instance.send(:define_method, name, block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_code_method(name, code)
|
41
|
+
@methods_def << <<-CODE
|
42
|
+
def #{name}
|
43
|
+
#{code}
|
44
|
+
end
|
45
|
+
CODE
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConcernBuilder do
|
4
|
+
class ConcernBuilder::Dummy
|
5
|
+
def initialize
|
6
|
+
@value = 0
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ConcernBuilder::Dummy::Builder < ConcernBuilder
|
11
|
+
def init
|
12
|
+
add_method(:blocked) { 1 }
|
13
|
+
add_method(:defined, "@value = @value + #{ options_object.try(:increment) || 1 }")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:options) { {} }
|
18
|
+
let(:dummy_builder) { ConcernBuilder::Dummy::Builder }
|
19
|
+
let(:builder) { dummy_builder.new([], ConcernBuilder::Dummy, options) }
|
20
|
+
let(:instance) { ConcernBuilder::Dummy.new }
|
21
|
+
|
22
|
+
before do
|
23
|
+
builder.build
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when describing a method with block' do
|
27
|
+
it 'creates a method with the block' do
|
28
|
+
expect(instance.blocked).to eq(1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when describing a method with string' do
|
33
|
+
it 'creates a method using the string definition' do
|
34
|
+
expect(instance.defined).to eq(1)
|
35
|
+
expect(instance.defined).to eq(2)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when passing options' do
|
40
|
+
let(:options) { { increment: 2 } }
|
41
|
+
it 'parses the options' do
|
42
|
+
expect(instance.defined).to eq(2)
|
43
|
+
expect(instance.defined).to eq(4)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'concern_builder'
|
5
|
+
|
6
|
+
support_files = File.expand_path("spec/support/**/*.rb")
|
7
|
+
Dir[support_files].each { |file| require file }
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
config.filter_run_excluding :integration unless ENV['ALL']
|
14
|
+
|
15
|
+
config.order = 'random'
|
16
|
+
|
17
|
+
config.before do
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module FixtureHelpers
|
4
|
+
def load_fixture_file(filename)
|
5
|
+
File.read (['./spec/', 'fixtures', filename].join('/'))
|
6
|
+
end
|
7
|
+
|
8
|
+
def load_json_fixture_file(filename)
|
9
|
+
cached_json_fixture_file(filename)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def cached_json_fixture_file(filename)
|
15
|
+
ActiveSupport::JSON.decode(load_fixture_file(filename))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configuration.include FixtureHelpers
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: concern_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DarthJee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-03 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Gem for easy concern creation
|
84
|
+
email:
|
85
|
+
- darthjee@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- concern_builder.gemspec
|
97
|
+
- lib/concern_builder.rb
|
98
|
+
- lib/concern_builder/options_parser.rb
|
99
|
+
- lib/concern_builder/version.rb
|
100
|
+
- spec/lib/concern_builder_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/support/fixture_helpers.rb
|
103
|
+
homepage: https://github.com/darthjee/concern_builder
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.4.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Gem for easy concern creation
|
126
|
+
test_files: []
|