dsl_accessors 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dsl_accessors.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ This gem is fully compatible to the built-in attr_accessor.
2
+
3
+ # Installation
4
+
5
+ Include the gem in your Gemfile:
6
+
7
+ gem 'dsl_accessors'
8
+
9
+ # Usage
10
+
11
+ require 'dsl_accessors'
12
+ class MyClass
13
+ include DslAccessors
14
+ attr_accessor :name
15
+ end
16
+
17
+ This generates 3 methods:
18
+
19
+ # this methods delegates to get_name if args.empty?. Otherwise it delegates to set_name
20
+ def name(*args)
21
+
22
+ # the getter method
23
+ def get_name
24
+
25
+ # the two setter methods
26
+ def set_name(value)
27
+
28
+ #delegates to set_name
29
+ def name=(value)
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "dsl_accessors/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "dsl_accessors"
7
+ s.version = DslAccessors::VERSION
8
+ s.authors = ["Robin Wenglewski"]
9
+ s.email = ["robin@wenglewski.de"]
10
+ s.homepage = "https://github.com/rweng/dsl_accessors"
11
+ s.summary = %q{dsl-like getters and setters with attr_accessor}
12
+ # s.description = %q{}
13
+
14
+ # s.rubyforge_project = "dsl_accessors"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency 'activesupport'
25
+ end
@@ -0,0 +1,30 @@
1
+ require "dsl_accessors/version"
2
+ require "active_support/concern"
3
+
4
+ module DslAccessors
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def attr_accessor *args
9
+ args.each do |attr|
10
+ class_eval <<-EOS, __FILE__, __LINE__ + 1
11
+ def set_#{attr}(value)
12
+ @#{attr} = value
13
+ end
14
+
15
+ def #{attr}=(value)
16
+ set_#{attr}(value)
17
+ end
18
+
19
+ def #{attr}(*args)
20
+ if args.empty?
21
+ @#{attr}
22
+ else
23
+ set_#{attr}(*args)
24
+ end
25
+ end
26
+ EOS
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module DslAccessors
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,67 @@
1
+ require 'dsl_accessors'
2
+
3
+ describe "DSL Accessors" do
4
+ before do
5
+ class DslTestClass
6
+ include DslAccessors
7
+ end
8
+ end
9
+
10
+ it "should provide the attr_accessor method" do
11
+ DslTestClass.should respond_to(:attr_accessor)
12
+ end
13
+
14
+ describe "Usage" do
15
+ before do
16
+ class DslTestClass
17
+ attr_accessor :blast
18
+ end
19
+
20
+ @c = DslTestClass.new
21
+ end
22
+
23
+ describe %q-set_#{accessor}- do
24
+ it "should exist" do
25
+ @c.should respond_to(:set_blast)
26
+ end
27
+
28
+ it "should set the @accessor attribute" do
29
+ @c.set_blast "testbla"
30
+ @c.instance_variable_get(:@blast).should eql("testbla")
31
+ end
32
+ end
33
+
34
+ describe %q-#{attr}=- do
35
+ it "should exist" do
36
+ @c.should respond_to(:blast=)
37
+ end
38
+
39
+ it %q-should delegate to set_#{attr}- do
40
+ @c.instance_eval do
41
+ def set_blast(value)
42
+ @blast = "works"
43
+ end
44
+ end
45
+ @c.blast = "does not work"
46
+ @c.instance_variable_get(:@blast).should eql("works")
47
+ end
48
+ end
49
+
50
+ describe %q-#{attr} method- do
51
+ it "should exist" do
52
+ @c.should respond_to :blast
53
+ end
54
+
55
+ it "should return the attribute when called with no parameters" do
56
+ @c.blast.should eql(@c.instance_variable_get(:@blast))
57
+ end
58
+
59
+ it "should set the attribute when called with a parameter" do
60
+ @c.blast("val")
61
+ @c.instance_variable_get(:@blast).should eql("val")
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsl_accessors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robin Wenglewski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70211547292640 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70211547292640
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70211547292220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70211547292220
36
+ description:
37
+ email:
38
+ - robin@wenglewski.de
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Rakefile
46
+ - Readme.md
47
+ - dsl_accessors.gemspec
48
+ - lib/dsl_accessors.rb
49
+ - lib/dsl_accessors/version.rb
50
+ - spec/dsl_accessor_spec.rb
51
+ homepage: https://github.com/rweng/dsl_accessors
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.10
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: dsl-like getters and setters with attr_accessor
75
+ test_files:
76
+ - spec/dsl_accessor_spec.rb