ztk 1.4.8 → 1.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ztk/dsl/core/attributes.rb +5 -3
- data/lib/ztk/dsl/core/options.rb +25 -0
- data/lib/ztk/dsl/core.rb +7 -5
- data/lib/ztk/version.rb +1 -1
- data/spec/ztk/dsl_spec.rb +11 -0
- metadata +4 -3
@@ -6,23 +6,25 @@ module ZTK::DSL::Core
|
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base.class_eval do
|
9
|
+
base.send(:extend, ZTK::DSL::Core::Options::ClassMethods)
|
10
|
+
base.add_option(:attribute)
|
9
11
|
base.send(:extend, ZTK::DSL::Core::Attributes::ClassMethods)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
15
|
def attributes
|
14
|
-
@attributes ||=
|
16
|
+
@attributes ||= Hash.new
|
15
17
|
end
|
16
18
|
|
17
19
|
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
18
20
|
module ClassMethods
|
19
21
|
|
20
22
|
def attribute(key, options={})
|
21
|
-
|
22
|
-
@attributes[key] = options[:default]
|
23
|
+
attribute_options[key] = options
|
23
24
|
|
24
25
|
send(:define_method, key) do |*args|
|
25
26
|
if args.count == 0
|
27
|
+
attributes[key] ||= self.class.attribute_options[key][:default]
|
26
28
|
attributes[key]
|
27
29
|
else
|
28
30
|
send("#{key}=", *args)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ZTK::DSL::Core
|
2
|
+
|
3
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
4
|
+
# @api private
|
5
|
+
module Options
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
base.send(:extend, ZTK::DSL::Core::Options::ClassMethods)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
14
|
+
module ClassMethods
|
15
|
+
|
16
|
+
def add_option(key)
|
17
|
+
option_key = "#{key}_options"
|
18
|
+
cattr_accessor option_key
|
19
|
+
send(option_key) || send("#{option_key}=", {})
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/ztk/dsl/core.rb
CHANGED
@@ -5,11 +5,12 @@ module ZTK::DSL
|
|
5
5
|
# @author Zachary Patten <zachary AT jovelabs DOT com>
|
6
6
|
# @api private
|
7
7
|
module Core
|
8
|
-
autoload :Attributes,
|
9
|
-
autoload :Actions,
|
10
|
-
autoload :Dataset,
|
11
|
-
autoload :IO,
|
12
|
-
autoload :
|
8
|
+
autoload :Attributes, 'ztk/dsl/core/attributes'
|
9
|
+
autoload :Actions, 'ztk/dsl/core/actions'
|
10
|
+
autoload :Dataset, 'ztk/dsl/core/dataset'
|
11
|
+
autoload :IO, 'ztk/dsl/core/io'
|
12
|
+
autoload :Options, 'ztk/dsl/core/options'
|
13
|
+
autoload :Relations, 'ztk/dsl/core/relations'
|
13
14
|
|
14
15
|
def self.included(base)
|
15
16
|
base.class_eval do
|
@@ -22,6 +23,7 @@ module ZTK::DSL
|
|
22
23
|
base.send(:include, ZTK::DSL::Core::Actions)
|
23
24
|
base.send(:include, ZTK::DSL::Core::Dataset)
|
24
25
|
base.send(:include, ZTK::DSL::Core::IO)
|
26
|
+
base.send(:include, ZTK::DSL::Core::Options)
|
25
27
|
base.send(:include, ZTK::DSL::Core::Relations)
|
26
28
|
end
|
27
29
|
end
|
data/lib/ztk/version.rb
CHANGED
data/spec/ztk/dsl_spec.rb
CHANGED
@@ -64,6 +64,17 @@ describe ZTK::DSL do
|
|
64
64
|
dsl_test.name.should == data
|
65
65
|
end
|
66
66
|
|
67
|
+
it "should allow setting a default value for an attribute" do
|
68
|
+
data = "Hello World"
|
69
|
+
class DSLTest < ZTK::DSL::Base
|
70
|
+
attribute :name, :default => "Hello World"
|
71
|
+
end
|
72
|
+
|
73
|
+
dsl_test = DSLTest.new
|
74
|
+
|
75
|
+
dsl_test.name.should == data
|
76
|
+
end
|
77
|
+
|
67
78
|
it "should throw an exception when setting an invalid attribute" do
|
68
79
|
data = "Hello World @ #{Time.now.utc}"
|
69
80
|
class DSLTest < ZTK::DSL::Base
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- lib/ztk/dsl/core/attributes.rb
|
207
207
|
- lib/ztk/dsl/core/dataset.rb
|
208
208
|
- lib/ztk/dsl/core/io.rb
|
209
|
+
- lib/ztk/dsl/core/options.rb
|
209
210
|
- lib/ztk/dsl/core/relations.rb
|
210
211
|
- lib/ztk/dsl/core/relations/belongs_to.rb
|
211
212
|
- lib/ztk/dsl/core/relations/has_many.rb
|
@@ -264,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
264
265
|
version: '0'
|
265
266
|
segments:
|
266
267
|
- 0
|
267
|
-
hash:
|
268
|
+
hash: 2449655142974466757
|
268
269
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
269
270
|
none: false
|
270
271
|
requirements:
|
@@ -273,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
274
|
version: '0'
|
274
275
|
segments:
|
275
276
|
- 0
|
276
|
-
hash:
|
277
|
+
hash: 2449655142974466757
|
277
278
|
requirements: []
|
278
279
|
rubyforge_project:
|
279
280
|
rubygems_version: 1.8.25
|