adv_accessor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +20 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/adv_accessor.rb +7 -0
- data/lib/adv_accessor/base.rb +27 -0
- data/lib/adv_accessor/checker.rb +17 -0
- data/lib/adv_accessor/dsl.rb +90 -0
- data/lib/adv_accessor/mapping.rb +68 -0
- data/spec/adv_accessor_spec.rb +208 -0
- data/spec/spec_helper.rb +12 -0
- metadata +158 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
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 'mharris_ext'
|
9
|
+
gem 'fattr'
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.2.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.5.1"
|
14
|
+
#gem "rcov", ">= 0"
|
15
|
+
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
facets (2.8.4)
|
6
|
+
fattr (2.1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.5.1)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
mharris_ext (1.5.0)
|
13
|
+
facets
|
14
|
+
fattr
|
15
|
+
rake (0.8.7)
|
16
|
+
rspec (2.2.0)
|
17
|
+
rspec-core (~> 2.2)
|
18
|
+
rspec-expectations (~> 2.2)
|
19
|
+
rspec-mocks (~> 2.2)
|
20
|
+
rspec-core (2.2.1)
|
21
|
+
rspec-expectations (2.2.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.2.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x86-mingw32
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
fattr
|
31
|
+
jeweler (~> 1.5.1)
|
32
|
+
mharris_ext
|
33
|
+
rspec (~> 2.2.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Mike Harris
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= adv_accessor
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to adv_accessor
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* 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.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Mike Harris. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
20
|
+
abc
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "adv_accessor"
|
16
|
+
gem.homepage = "http://github.com/mharris717/adv_accessor"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{adv_accessor}
|
19
|
+
gem.description = %Q{adv_accessor}
|
20
|
+
gem.email = "mharris717@gmail.com"
|
21
|
+
gem.authors = ["Mike Harris"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "adv_accessor #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/adv_accessor.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module AdvAccessor
|
2
|
+
class Base
|
3
|
+
include FromHash
|
4
|
+
attr_accessor :method
|
5
|
+
attr_accessor :null_value
|
6
|
+
attr_accessor :reader
|
7
|
+
def value=(x)
|
8
|
+
@input_value = @value = x
|
9
|
+
end
|
10
|
+
def raw_value
|
11
|
+
return @value if @value
|
12
|
+
@value = null_value[] if null_value
|
13
|
+
@value
|
14
|
+
end
|
15
|
+
def basic_value
|
16
|
+
res = raw_value
|
17
|
+
res = reader[res] if reader
|
18
|
+
res
|
19
|
+
end
|
20
|
+
def value(type=nil)
|
21
|
+
return basic_value unless type
|
22
|
+
readers.get(type)
|
23
|
+
end
|
24
|
+
fattr(:mappings) { AdvAccessor::Mappings.new(:base => self) }
|
25
|
+
fattr(:readers) { AdvAccessor::Readers.new(:base => self) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AdvAccessor
|
2
|
+
class Checker
|
3
|
+
include FromHash
|
4
|
+
attr_accessor :obj
|
5
|
+
def match?(o)
|
6
|
+
if obj.kind_of?(Proc)
|
7
|
+
!!obj[o]
|
8
|
+
elsif obj.kind_of?(Class)
|
9
|
+
o.kind_of?(obj)
|
10
|
+
elsif obj.kind_of?(Regexp)
|
11
|
+
!!(o =~ obj)
|
12
|
+
else
|
13
|
+
o == obj
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module AdvAccessor
|
2
|
+
def self.included(mod)
|
3
|
+
mod.send(:extend,AdvAccessor::DSL::BaseInclude)
|
4
|
+
end
|
5
|
+
module DSL
|
6
|
+
class Create
|
7
|
+
attr_accessor :base, :complex
|
8
|
+
include FromHash
|
9
|
+
def method_missing(sym,*args,&b)
|
10
|
+
if base.respond_to?(sym)
|
11
|
+
base.send(sym,*args,&b)
|
12
|
+
else
|
13
|
+
self.complex = true
|
14
|
+
if !block_given? && args.first.kind_of?(Proc)
|
15
|
+
b = args.pop
|
16
|
+
end
|
17
|
+
if args.first.kind_of?(Hash)
|
18
|
+
h = args.pop
|
19
|
+
mappings.add(h,&b)
|
20
|
+
base.readers.add(sym,h.values.first)
|
21
|
+
else
|
22
|
+
base.readers.add(sym,*args,&b)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
class Access
|
29
|
+
attr_accessor :base
|
30
|
+
include FromHash
|
31
|
+
def raw
|
32
|
+
value
|
33
|
+
end
|
34
|
+
def method_missing(sym,*args,&b)
|
35
|
+
if base.respond_to?(sym)
|
36
|
+
base.send(sym,*args,&b)
|
37
|
+
else
|
38
|
+
base.readers.get(sym)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module BaseInclude
|
44
|
+
def adv_accessor(name,&b)
|
45
|
+
@adv_accessor ||= Hash.new { |h,k| h[k] = AdvAccessor::Base.new(:method => name) }
|
46
|
+
|
47
|
+
base = @adv_accessor[name]
|
48
|
+
dsl = AdvAccessor::DSL::Create.new(:base => base)
|
49
|
+
|
50
|
+
complex_block = lambda do
|
51
|
+
block = b
|
52
|
+
if b.arity == 0
|
53
|
+
block = lambda { |a| a.null_value = b }
|
54
|
+
end
|
55
|
+
block
|
56
|
+
end
|
57
|
+
|
58
|
+
create_writer = lambda do
|
59
|
+
define_method("#{name}=") do |arg|
|
60
|
+
base.value = arg
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
create_simple = lambda do
|
65
|
+
define_method(name) do
|
66
|
+
base.value
|
67
|
+
end
|
68
|
+
create_writer[]
|
69
|
+
end
|
70
|
+
|
71
|
+
create_complex = lambda do
|
72
|
+
define_method(name) do
|
73
|
+
AdvAccessor::DSL::Access.new(:base => base)
|
74
|
+
end
|
75
|
+
create_writer[]
|
76
|
+
end
|
77
|
+
|
78
|
+
if block_given?
|
79
|
+
complex_block[][dsl]
|
80
|
+
if dsl.complex
|
81
|
+
create_complex[]
|
82
|
+
else
|
83
|
+
create_simple[]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module AdvAccessor
|
3
|
+
class Mapping
|
4
|
+
attr_accessor :from, :to, :block, :base
|
5
|
+
include FromHash
|
6
|
+
def match?(ops)
|
7
|
+
if base.act_on_array && ops[:val].kind_of?(Array)
|
8
|
+
from == ops[:val].first.class && to == ops[:to]
|
9
|
+
else
|
10
|
+
from == ops[:val].class && to == ops[:to]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class Reader
|
15
|
+
attr_accessor :name, :block
|
16
|
+
include FromHash
|
17
|
+
def match?(ops)
|
18
|
+
name == ops[:name]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
class BaseReaders
|
22
|
+
include FromHash
|
23
|
+
attr_accessor :base
|
24
|
+
fattr(:list) { [] }
|
25
|
+
def <<(x)
|
26
|
+
self.list << x
|
27
|
+
end
|
28
|
+
def get(ops)
|
29
|
+
ops[:val] ||= base.value
|
30
|
+
list.each do |m|
|
31
|
+
if m.match?(ops)
|
32
|
+
os = OpenStruct.new(:value => ops[:val], :raw_value => base.raw_value)
|
33
|
+
return m.block[os]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
raise "cant convert #{ops.inspect}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
class Mappings < BaseReaders
|
40
|
+
fattr(:act_on_array) { false }
|
41
|
+
def add(ops,&b)
|
42
|
+
ops.each do |from,to|
|
43
|
+
self << Mapping.new(:from => from, :to => to, :block => b, :base => self)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
def get(arg)
|
47
|
+
arg = {:from => base.value.class, :to => arg} unless arg.kind_of?(Hash)
|
48
|
+
arg[:from] ||= base.value.class
|
49
|
+
if act_on_array && base.value.kind_of?(Array)
|
50
|
+
base.value.map do |val|
|
51
|
+
super(arg.merge(:val => val))
|
52
|
+
end
|
53
|
+
else
|
54
|
+
super(arg)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
class Readers < BaseReaders
|
59
|
+
def add(name,cls=nil,&b)
|
60
|
+
b = lambda { |x| base.mappings.get(cls) } if cls
|
61
|
+
self << Reader.new(:name => name, :block => b)
|
62
|
+
end
|
63
|
+
def get(arg)
|
64
|
+
arg = {:name => arg} unless arg.kind_of?(Hash)
|
65
|
+
super(arg)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "AdvAccessor::Base" do
|
4
|
+
def base; @base; end
|
5
|
+
describe "basic getting and setting" do
|
6
|
+
before do
|
7
|
+
@nv_log = []
|
8
|
+
@base = AdvAccessor::Base.new
|
9
|
+
base.null_value = lambda do
|
10
|
+
@nv_log << "Called"
|
11
|
+
13
|
12
|
+
end
|
13
|
+
end
|
14
|
+
it "sets null value" do
|
15
|
+
base.value.should == 13
|
16
|
+
end
|
17
|
+
it "only sets null value once" do
|
18
|
+
3.times { |x| base.value }
|
19
|
+
@nv_log.size.should == 1
|
20
|
+
base.value.should == 13
|
21
|
+
end
|
22
|
+
it "can set value" do
|
23
|
+
base.value = 14
|
24
|
+
base.value.should == 14
|
25
|
+
@nv_log.size.should == 0
|
26
|
+
end
|
27
|
+
it "can overwrite null value" do
|
28
|
+
base.value.should == 13
|
29
|
+
base.value = 14
|
30
|
+
base.value.should == 14
|
31
|
+
end
|
32
|
+
end
|
33
|
+
describe "mapped value" do
|
34
|
+
before do
|
35
|
+
@base = AdvAccessor::Base.new
|
36
|
+
base.mappings.add(Fixnum => String) { |x| x.value.to_s + "X" }
|
37
|
+
base.value = 13
|
38
|
+
end
|
39
|
+
it "should get mapped value" do
|
40
|
+
base.mappings.get(String).should == "13X"
|
41
|
+
end
|
42
|
+
it "should raw exception if value can't be mapped" do
|
43
|
+
lambda { base.mappings.get(Symbol) }.should raise_error(Exception)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe "mapped array value" do
|
47
|
+
before do
|
48
|
+
@base = AdvAccessor::Base.new
|
49
|
+
base.mappings.act_on_array = true
|
50
|
+
base.mappings.add(Fixnum => String) { |x| x.value.to_s + "X" }
|
51
|
+
base.value = [1,2]
|
52
|
+
end
|
53
|
+
it "should get mapped value" do
|
54
|
+
base.mappings.get(String).should == ["1X","2X"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe "reader, writer, raw" do
|
58
|
+
before do
|
59
|
+
@base = AdvAccessor::Base.new
|
60
|
+
base.reader = lambda { |x| x * 2 }
|
61
|
+
base.value = 13
|
62
|
+
end
|
63
|
+
it "should read" do
|
64
|
+
base.value.should == 26
|
65
|
+
end
|
66
|
+
it 'has raw value' do
|
67
|
+
base.raw_value.should == 13
|
68
|
+
end
|
69
|
+
end
|
70
|
+
describe "special accessors" do
|
71
|
+
before do
|
72
|
+
@base = AdvAccessor::Base.new
|
73
|
+
base.value = 13
|
74
|
+
base.readers.add(:times_two) do |a|
|
75
|
+
a.raw_value * 2
|
76
|
+
end
|
77
|
+
end
|
78
|
+
it "should read" do
|
79
|
+
base.value(:times_two).should == 26
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
describe "DSL" do
|
86
|
+
before do
|
87
|
+
@Foo = Class.new do
|
88
|
+
include AdvAccessor
|
89
|
+
end
|
90
|
+
end
|
91
|
+
fattr(:f) { @Foo.new }
|
92
|
+
def aa
|
93
|
+
@Foo.instance_eval { @adv_accessor }
|
94
|
+
end
|
95
|
+
it "smoke" do
|
96
|
+
@Foo.adv_accessor(:bar)
|
97
|
+
end
|
98
|
+
it "basic accessor" do
|
99
|
+
@Foo.adv_accessor(:bar) { 14 }
|
100
|
+
@Foo.new.bar.should == 14
|
101
|
+
end
|
102
|
+
it 'complex accessor' do
|
103
|
+
@Foo.adv_accessor(:bar) do |a|
|
104
|
+
a.null_value = lambda { 14 }
|
105
|
+
end
|
106
|
+
@Foo.new.bar.should == 14
|
107
|
+
end
|
108
|
+
it 'basic writer' do
|
109
|
+
@Foo.adv_accessor(:bar) { 14 }
|
110
|
+
f = @Foo.new
|
111
|
+
f.bar = 15
|
112
|
+
f.bar.should == 15
|
113
|
+
end
|
114
|
+
describe 'mapped reader' do
|
115
|
+
before do
|
116
|
+
@Foo.adv_accessor(:bar) do |a|
|
117
|
+
a.num { |a| a.value.to_i }
|
118
|
+
end
|
119
|
+
f.bar = "15"
|
120
|
+
end
|
121
|
+
it "should have value" do
|
122
|
+
@Foo.instance_eval { @adv_accessor }[:bar].value.should == "15"
|
123
|
+
end
|
124
|
+
it "should have reader value in base" do
|
125
|
+
|
126
|
+
@Foo.instance_eval { @adv_accessor }[:bar].readers.get(:num).should == 15
|
127
|
+
end
|
128
|
+
it "should have reader value access with method" do
|
129
|
+
f.bar.num.should == 15
|
130
|
+
end
|
131
|
+
it "should have raw access with method" do
|
132
|
+
f.bar.raw.should == '15'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
describe 'mapped reader by class - verbose' do
|
136
|
+
before do
|
137
|
+
@Foo.adv_accessor(:bar) do |a|
|
138
|
+
a.mappings.add(String => Fixnum) { |x| x.value.to_i }
|
139
|
+
a.num(Fixnum)
|
140
|
+
end
|
141
|
+
f.bar = "15"
|
142
|
+
end
|
143
|
+
it 'should have mapping set' do
|
144
|
+
aa[:bar].mappings.get(Fixnum).should == 15
|
145
|
+
end
|
146
|
+
it "should have accessor" do
|
147
|
+
f.bar.num.should == 15
|
148
|
+
end
|
149
|
+
end
|
150
|
+
describe 'mapped reader by class - concise' do
|
151
|
+
before do
|
152
|
+
@Foo.adv_accessor(:bar) do |a|
|
153
|
+
a.num(String => Fixnum) { |x| x.value.to_i }
|
154
|
+
end
|
155
|
+
f.bar = "15"
|
156
|
+
end
|
157
|
+
it 'should have mapping set' do
|
158
|
+
aa[:bar].mappings.get(Fixnum).should == 15
|
159
|
+
end
|
160
|
+
it "should have accessor" do
|
161
|
+
f.bar.num.should == 15
|
162
|
+
end
|
163
|
+
end
|
164
|
+
describe 'mapped reader by class - array' do
|
165
|
+
before do
|
166
|
+
@Foo.adv_accessor(:bar) do |a|
|
167
|
+
a.mappings.act_on_array = true
|
168
|
+
a.num(String => Fixnum) { |x| x.value.to_i }
|
169
|
+
end
|
170
|
+
f.bar = ["1","2"]
|
171
|
+
end
|
172
|
+
it 'should have mapping set' do
|
173
|
+
aa[:bar].mappings.get(Fixnum).should == [1,2]
|
174
|
+
end
|
175
|
+
it "should have accessor" do
|
176
|
+
f.bar.num.should == [1,2]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
if false
|
182
|
+
class Foo
|
183
|
+
adv_accessor :abc
|
184
|
+
adv_accessor(:abc) do
|
185
|
+
14
|
186
|
+
end
|
187
|
+
adv_accessor.complex(:abc) do |a|
|
188
|
+
a.null_value = lambda { 14 }
|
189
|
+
end
|
190
|
+
adv_accessor.complex(:abc) do |a|
|
191
|
+
a.reader = lambda do |a|
|
192
|
+
a*2
|
193
|
+
end
|
194
|
+
end
|
195
|
+
adv_accessor.complex(:grouping) do |a|
|
196
|
+
a.cols = lambda do |a|
|
197
|
+
a.raw.map { |f| f.kind_of?(DW::Field) ? f.col_alias : f }
|
198
|
+
end
|
199
|
+
a.fields = lambda do |a|
|
200
|
+
a.cols.map { |x| new_sql_field(:field => x) }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
adv_accessor.complex(:grouping) do |a|
|
204
|
+
a.mapping(String => DW::Field) { |x| new_sql_field(:field => x) }
|
205
|
+
a.mapped_accessor(:cols => String, :fields => DW::Field)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'adv_accessor'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adv_accessor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mike Harris
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-17 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mharris_ext
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: fattr
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 7
|
57
|
+
segments:
|
58
|
+
- 2
|
59
|
+
- 2
|
60
|
+
- 0
|
61
|
+
version: 2.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: bundler
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 23
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
version: 1.0.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: jeweler
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 1
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 5
|
92
|
+
- 1
|
93
|
+
version: 1.5.1
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: *id005
|
97
|
+
description: adv_accessor
|
98
|
+
email: mharris717@gmail.com
|
99
|
+
executables: []
|
100
|
+
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.rdoc
|
106
|
+
files:
|
107
|
+
- .document
|
108
|
+
- .rspec
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.rdoc
|
113
|
+
- Rakefile
|
114
|
+
- VERSION
|
115
|
+
- lib/adv_accessor.rb
|
116
|
+
- lib/adv_accessor/base.rb
|
117
|
+
- lib/adv_accessor/checker.rb
|
118
|
+
- lib/adv_accessor/dsl.rb
|
119
|
+
- lib/adv_accessor/mapping.rb
|
120
|
+
- spec/adv_accessor_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
has_rdoc: true
|
123
|
+
homepage: http://github.com/mharris717/adv_accessor
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.3.7
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: adv_accessor
|
156
|
+
test_files:
|
157
|
+
- spec/adv_accessor_spec.rb
|
158
|
+
- spec/spec_helper.rb
|