trax_core 0.0.80 → 0.0.81
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/lib/trax/core.rb +3 -0
- data/lib/trax/core/blueprint.rb +15 -0
- data/lib/trax/core/errors.rb +9 -0
- data/lib/trax/core/ext/object.rb +1 -1
- data/lib/trax/core/fs.rb +8 -0
- data/lib/trax/core/has_dependencies.rb +44 -0
- data/lib/trax/core/named_class.rb +7 -3
- data/lib/trax/core/silence_warnings.rb +17 -0
- data/lib/trax/core/types.rb +2 -0
- data/lib/trax/core/types/array.rb +7 -0
- data/lib/trax/core/types/array_of.rb +15 -0
- data/lib/trax/core/types/behaviors.rb +11 -0
- data/lib/trax/core/types/behaviors/array_of_members.rb +34 -0
- data/lib/trax/core/types/enum.rb +22 -12
- data/lib/trax/core/types/enum_value.rb +10 -1
- data/lib/trax/core/types/struct.rb +10 -10
- data/lib/trax_core/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/trax/core/has_dependencies_spec.rb +60 -0
- data/spec/trax/core/types/array_spec.rb +28 -0
- data/spec/trax/core/types/struct_spec.rb +5 -0
- metadata +13 -6
- data/spec/support/category_enum.rb +0 -6
- data/spec/trax/enum_spec.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e6a4cb955ae996c2b8941aebb6e4e80013aa35
|
4
|
+
data.tar.gz: 50dd9c4f7fe2ca36378c597dc704fdd237a8a4a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d36c531fe5f70a9fab622b66c09e109a5fa3bb5c9ad0e1566ad14f7e8e2bf5d188a9203902f24c4754f680bc0ed4897436bb7a4491023a275006683d3d175b5b
|
7
|
+
data.tar.gz: 1600fa9f8511c58cd69c23d90ee17bbd7581eb65cdd5adc1d11bce0d69a73b342371008ecc05358dfd34eedd6a1d8eeff6ae11061ff9eb27ce46645855c7ca0a
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/lib/trax/core.rb
CHANGED
@@ -18,6 +18,7 @@ module Trax
|
|
18
18
|
extend ::ActiveSupport::Autoload
|
19
19
|
|
20
20
|
autoload :AbstractMethods
|
21
|
+
autoload :Blueprint
|
21
22
|
autoload :Configuration
|
22
23
|
autoload :Concern
|
23
24
|
autoload :Definition
|
@@ -28,11 +29,13 @@ module Trax
|
|
28
29
|
autoload :Fields
|
29
30
|
autoload :FS
|
30
31
|
autoload :HasMixins
|
32
|
+
autoload :HasDependencies
|
31
33
|
autoload :InheritanceHooks
|
32
34
|
autoload :Mixin
|
33
35
|
autoload :Mixable
|
34
36
|
autoload :NamedClass
|
35
37
|
autoload :NamedModule
|
38
|
+
autoload :SilenceWarnings
|
36
39
|
autoload :Types
|
37
40
|
end
|
38
41
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Trax
|
2
|
+
module Core
|
3
|
+
class Blueprint < ::Trax::Core::Types::Struct
|
4
|
+
def self.const_missing(const_name)
|
5
|
+
if fields.const_defined?(const_name, false)
|
6
|
+
result = const_set(const_name, fields.const_get(const_name)) if fields.const_defined?(const_name, false)
|
7
|
+
else
|
8
|
+
result = super(const_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/trax/core/errors.rb
CHANGED
@@ -93,6 +93,15 @@ module Trax
|
|
93
93
|
}
|
94
94
|
end
|
95
95
|
|
96
|
+
class MissingRequiredDependency < ::Trax::Core::Errors::Base
|
97
|
+
argument :source
|
98
|
+
argument :missing_dependencies
|
99
|
+
|
100
|
+
message {
|
101
|
+
"#{source} was initialized without required dependencies, #{missing_dependencies.join(', ')}"
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
96
105
|
class MixinNotRegistered < ::Trax::Core::Errors::Base
|
97
106
|
argument :mixin
|
98
107
|
argument :source
|
data/lib/trax/core/ext/object.rb
CHANGED
@@ -60,7 +60,7 @@ class Object
|
|
60
60
|
segs = const_name.split("::")
|
61
61
|
|
62
62
|
raise(::StandardError.new("Set fully qualified constant requires a preexisting namespace to set under")) unless segs.length > 1
|
63
|
-
|
63
|
+
|
64
64
|
as, on = segs.pop, segs.join("::").constantize
|
65
65
|
on.const_set(as, value)
|
66
66
|
end
|
data/lib/trax/core/fs.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Trax
|
2
|
+
module Core
|
3
|
+
module HasDependencies
|
4
|
+
def self.included(klass)
|
5
|
+
klass.class_attribute :_depends_on
|
6
|
+
klass.class_attribute :_depends_on_config
|
7
|
+
klass._depends_on_config = {}
|
8
|
+
klass._depends_on = []
|
9
|
+
klass.extend(ClassMethods)
|
10
|
+
klass.prepend(InstanceMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def depends_on(*args, pass_options_to_super:true)
|
15
|
+
self._depends_on += args
|
16
|
+
self._depends_on.map{|_dependency_key| self.__send__("attr_reader", _dependency_key) }
|
17
|
+
self._depends_on_config[:pass_options_to_super] = pass_options_to_super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
def initialize(*args, **options)
|
23
|
+
if self.class._depends_on.length
|
24
|
+
missing_dependencies = self.class._depends_on.select{|k| !options.key?(k) }
|
25
|
+
|
26
|
+
if missing_dependencies.any?
|
27
|
+
raise ::Trax::Core::Errors::MissingRequiredDependency.new(:source => self.class, :missing_dependencies => missing_dependencies)
|
28
|
+
else
|
29
|
+
options.extract!(*self._depends_on).each_pair do |k,v|
|
30
|
+
instance_variable_set("@#{k}", v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if self.class._depends_on_config[:pass_options_to_super]
|
36
|
+
super(*args, **options)
|
37
|
+
else
|
38
|
+
super(*args)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module Trax
|
2
2
|
module Core
|
3
3
|
class NamedClass
|
4
|
+
include ::Trax::Core::SilenceWarnings
|
5
|
+
|
4
6
|
def self.new(_name, _parent_klass=Object, **options, &block)
|
5
|
-
klass =
|
6
|
-
|
7
|
-
|
7
|
+
klass = silence_warnings {
|
8
|
+
::Object.set_fully_qualified_constant(_name, ::Class.new(_parent_klass) {
|
9
|
+
define_singleton_method(:name) { _name }
|
10
|
+
})
|
11
|
+
}
|
8
12
|
|
9
13
|
options.each_pair do |k,v|
|
10
14
|
klass.class_attribute k
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Trax
|
2
|
+
module Core
|
3
|
+
module SilenceWarnings
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def silence_warnings
|
8
|
+
original_verbosity = $VERBOSE
|
9
|
+
$VERBOSE = nil
|
10
|
+
result = yield
|
11
|
+
$VERBOSE = original_verbosity
|
12
|
+
return result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/trax/core/types.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Trax
|
2
|
+
module Core
|
3
|
+
module Types
|
4
|
+
module Behaviors
|
5
|
+
module ArrayOfMembers
|
6
|
+
extend ::ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ::Enumerable
|
10
|
+
|
11
|
+
class_attribute :member_class
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
super([args].flatten.compact)
|
16
|
+
self.map!{ |ele| self.class.member_class.new(ele) } if self.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
def <<(val)
|
20
|
+
if self.class.member_class && val.class == self.class.member_class
|
21
|
+
super(val)
|
22
|
+
else
|
23
|
+
super(self.class.member_class.new(val))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def each(&block)
|
28
|
+
yield __getobj__.each(&block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/trax/core/types/enum.rb
CHANGED
@@ -15,7 +15,7 @@ module Trax
|
|
15
15
|
class_attribute :allow_nil, :raise_on_invalid
|
16
16
|
|
17
17
|
### Class Methods ###
|
18
|
-
def self.define_enum_value(const_name, val=nil)
|
18
|
+
def self.define_enum_value(const_name, val=nil, **attributes)
|
19
19
|
name = "#{const_name}".underscore.to_sym
|
20
20
|
const_name = name.to_s.camelize
|
21
21
|
val = (self._values_hash.length + 1) if val.nil?
|
@@ -23,25 +23,18 @@ module Trax
|
|
23
23
|
raise ::Trax::Core::Errors::DuplicateEnumValue.new(:klass => self.class.name, :value => const_name) if self === name
|
24
24
|
raise ::Trax::Core::Errors::DuplicateEnumValue.new(:klass => self.class.name, :value => val) if self === val
|
25
25
|
|
26
|
-
value_klass = self.
|
26
|
+
value_klass = ::Trax::Core::NamedClass.new("#{self.name}::#{const_name}", ::Trax::Core::Types::EnumValue){
|
27
27
|
self.tag = name
|
28
28
|
self.value = val
|
29
|
-
|
29
|
+
self.attributes = attributes
|
30
|
+
}
|
30
31
|
|
31
32
|
self._values_hash[val] = value_klass
|
32
33
|
self._names_hash[name] = value_klass
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.[](val)
|
36
|
-
|
37
|
-
self._values_hash[val]
|
38
|
-
elsif ::Is.symbolic?(val)
|
39
|
-
val = val.to_sym if val.is_a?(::String)
|
40
|
-
self._names_hash[val]
|
41
|
-
elsif val.superclass.name == "Trax::Core::Types::EnumValue"
|
42
|
-
val = val.to_sym
|
43
|
-
self._names_hash[val]
|
44
|
-
end
|
37
|
+
find_enum_value(val)
|
45
38
|
end
|
46
39
|
|
47
40
|
def self.as_json(options={})
|
@@ -63,6 +56,23 @@ module Trax
|
|
63
56
|
args.map{|arg| self[arg].to_i }
|
64
57
|
end
|
65
58
|
|
59
|
+
def self.select_enum_values(*args)
|
60
|
+
args.flat_compact_uniq!
|
61
|
+
args.map{ |arg| find_enum_value(arg) }.compact
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find_enum_value(val)
|
65
|
+
if ::Is.numeric?(val)
|
66
|
+
self._values_hash[val]
|
67
|
+
elsif ::Is.symbolic?(val)
|
68
|
+
val = val.to_sym if val.is_a?(::String)
|
69
|
+
self._names_hash[val]
|
70
|
+
elsif val.superclass.name == "Trax::Core::Types::EnumValue"
|
71
|
+
val = val.to_sym
|
72
|
+
self._names_hash[val]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
66
76
|
def self.define(*args)
|
67
77
|
define_enum_value(*args)
|
68
78
|
end
|
@@ -2,7 +2,12 @@ module Trax
|
|
2
2
|
module Core
|
3
3
|
module Types
|
4
4
|
class EnumValue
|
5
|
-
|
5
|
+
def self.inherited(subclass)
|
6
|
+
super(subclass)
|
7
|
+
self.class_attribute(:tag)
|
8
|
+
self.class_attribute(:value)
|
9
|
+
self.class_attribute(:attributes)
|
10
|
+
end
|
6
11
|
|
7
12
|
def self.as_json(options={})
|
8
13
|
tag.to_s
|
@@ -28,6 +33,10 @@ module Trax
|
|
28
33
|
val == parent
|
29
34
|
end
|
30
35
|
|
36
|
+
def self.[](attribute_name)
|
37
|
+
attributes[attribute_name]
|
38
|
+
end
|
39
|
+
|
31
40
|
def self.to_schema
|
32
41
|
::Trax::Core::Definition.new(
|
33
42
|
:source => self.name,
|
@@ -15,13 +15,13 @@ module Trax
|
|
15
15
|
# It defeats the whole purpose of being a 'struct'
|
16
16
|
# if we fail to do so, and it makes our data far more error prone
|
17
17
|
DEFAULT_VALUES_FOR_PROPERTY_TYPES = {
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
18
|
+
:array => [],
|
19
|
+
:boolean => nil,
|
20
|
+
:float => 0.0,
|
21
|
+
:string => "",
|
22
|
+
:struct => {},
|
23
|
+
:enum => nil,
|
24
|
+
:integer => nil
|
25
25
|
}.with_indifferent_access.freeze
|
26
26
|
|
27
27
|
def self.fields_module
|
@@ -107,18 +107,18 @@ module Trax
|
|
107
107
|
#By default, strings/int/bool wont get cast to value objects
|
108
108
|
#mainly for the sake of performance/avoid unneccessary object allocation
|
109
109
|
def self.define_attribute_class_for_type(type_name, property_name, *args, coerce:false, **options, &block)
|
110
|
-
name = name.is_a?(Symbol) ? name.to_s : name
|
110
|
+
name = name.is_a?(::Symbol) ? name.to_s : name
|
111
111
|
klass_name = "#{fields_module.name.underscore}/#{property_name}".camelize
|
112
112
|
|
113
113
|
attribute_klass = if options.key?(:extend)
|
114
|
-
_klass_prototype = options[:extend].
|
114
|
+
_klass_prototype = options[:extend].is_a?(::String) ? options[:extend].safe_constantize : options[:extend]
|
115
115
|
_klass = ::Trax::Core::NamedClass.new(klass_name, _klass_prototype, :parent_definition => self, &block)
|
116
116
|
_klass
|
117
117
|
else
|
118
118
|
::Trax::Core::NamedClass.new(klass_name, "::Trax::Core::Types::#{type_name.to_s.classify}".constantize, :parent_definition => self, &block)
|
119
119
|
end
|
120
120
|
|
121
|
-
options[:default] = options.key?(:default) ? options[:default] : DEFAULT_VALUES_FOR_PROPERTY_TYPES[
|
121
|
+
options[:default] = options.key?(:default) ? options[:default] : DEFAULT_VALUES_FOR_PROPERTY_TYPES[type_name]
|
122
122
|
property(property_name.to_sym, *args, **options)
|
123
123
|
|
124
124
|
if coerce.is_a?(::Proc)
|
data/lib/trax_core/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Trax::Core::HasDependencies do
|
4
|
+
before(:all) do
|
5
|
+
class MyFakeItem
|
6
|
+
include ::Trax::Core::HasDependencies
|
7
|
+
|
8
|
+
attr_reader :my_options
|
9
|
+
|
10
|
+
def initialize(title, body, **options)
|
11
|
+
@title = title
|
12
|
+
@body = body
|
13
|
+
@my_options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
depends_on :organization, :pass_options_to_super => true
|
17
|
+
end
|
18
|
+
|
19
|
+
class MyFakeItemThatAcceptsNoOptions
|
20
|
+
include ::Trax::Core::HasDependencies
|
21
|
+
|
22
|
+
def initialize(title, body)
|
23
|
+
@title = title
|
24
|
+
@body = body
|
25
|
+
end
|
26
|
+
|
27
|
+
depends_on :organization, :pass_options_to_super => false
|
28
|
+
end
|
29
|
+
|
30
|
+
class MyFakeOrganization < Struct.new(:name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:organization) { MyFakeOrganization.new("whatever") }
|
35
|
+
let(:my_fake_item) { MyFakeItem.new("mytitle", "mybody", :organization => organization, my_other_thing: 'whatever') }
|
36
|
+
|
37
|
+
it "throws error if dependency not passed in" do
|
38
|
+
expect{ MyFakeItem.new }.to raise_error(::Trax::Core::Errors::MissingRequiredDependency)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets instance variables from dependency keys" do
|
42
|
+
expect(my_fake_item.organization).to eq(organization)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "allows options to be passed to it normally" do
|
46
|
+
expect(my_fake_item.my_options[:my_other_thing]).to eq 'whatever'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "rips out dependency keys from options when setting them" do
|
50
|
+
expect(my_fake_item.my_options).to_not have_key('organization')
|
51
|
+
end
|
52
|
+
|
53
|
+
context "no options accepted by super intialize" do
|
54
|
+
let(:my_fake_item) { ::MyFakeItemThatAcceptsNoOptions.new("mytitle", "mybody", :organization => organization) }
|
55
|
+
|
56
|
+
it "sets instance variables from dependency keys" do
|
57
|
+
expect(my_fake_item.organization).to eq(organization)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::Trax::Core::Types::Array do
|
4
|
+
before(:all) do
|
5
|
+
module AnotherFakeStructNamespace
|
6
|
+
extend ::Trax::Core::Definitions
|
7
|
+
struct :Widget do
|
8
|
+
integer :height, :default => 0
|
9
|
+
integer :width, :default => 0
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { ::Trax::Core::Types::Array.of(::AnotherFakeStructNamespace::Widget) }
|
15
|
+
|
16
|
+
context ".of" do
|
17
|
+
let(:test_subject) { subject.new({:width => 1}) }
|
18
|
+
it { test_subject[0].width.should eq 1 }
|
19
|
+
it { test_subject[0].height.should eq 0 }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "ArrayOf" do
|
23
|
+
subject { ::Trax::Core::Types::ArrayOf[::AnotherFakeStructNamespace::Widget] }
|
24
|
+
let(:test_subject) { subject.new({:width => 1}) }
|
25
|
+
it { test_subject[0].width.should eq 1 }
|
26
|
+
it { test_subject[0].height.should eq 0 }
|
27
|
+
end
|
28
|
+
end
|
@@ -9,6 +9,10 @@ describe ::Trax::Core::Types::Struct do
|
|
9
9
|
string :en, :default => ""
|
10
10
|
string :da, :default => ""
|
11
11
|
string :ca, :default => "eh"
|
12
|
+
|
13
|
+
struct :territories do
|
14
|
+
string :en, :default => "US"
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
@@ -19,6 +23,7 @@ describe ::Trax::Core::Types::Struct do
|
|
19
23
|
it { expect(subject.en).to eq "something" }
|
20
24
|
it { expect(subject.da).to eq "" }
|
21
25
|
it { expect(subject.ca).to eq "eh" }
|
26
|
+
it { expect(subject.territories.en).to eq "US" }
|
22
27
|
|
23
28
|
context "unknown value" do
|
24
29
|
subject { "::MyFakeStructNamespace::Locale".constantize.new(:blah => "something") }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trax_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.81
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Ayre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -173,6 +173,7 @@ extra_rdoc_files: []
|
|
173
173
|
files:
|
174
174
|
- ".gitignore"
|
175
175
|
- ".rspec"
|
176
|
+
- ".travis.yml"
|
176
177
|
- Gemfile
|
177
178
|
- Guardfile
|
178
179
|
- LICENSE.txt
|
@@ -181,6 +182,7 @@ files:
|
|
181
182
|
- lib/trax.rb
|
182
183
|
- lib/trax/core.rb
|
183
184
|
- lib/trax/core/abstract_methods.rb
|
185
|
+
- lib/trax/core/blueprint.rb
|
184
186
|
- lib/trax/core/concern.rb
|
185
187
|
- lib/trax/core/configuration.rb
|
186
188
|
- lib/trax/core/definition.rb
|
@@ -200,6 +202,7 @@ files:
|
|
200
202
|
- lib/trax/core/ext/uri.rb
|
201
203
|
- lib/trax/core/fields.rb
|
202
204
|
- lib/trax/core/fs.rb
|
205
|
+
- lib/trax/core/has_dependencies.rb
|
203
206
|
- lib/trax/core/has_mixins.rb
|
204
207
|
- lib/trax/core/inheritance_hooks.rb
|
205
208
|
- lib/trax/core/isolated_mixin.rb
|
@@ -209,8 +212,12 @@ files:
|
|
209
212
|
- lib/trax/core/named_module.rb
|
210
213
|
- lib/trax/core/primitives/enum.rb
|
211
214
|
- lib/trax/core/primitives/enum_value.rb
|
215
|
+
- lib/trax/core/silence_warnings.rb
|
212
216
|
- lib/trax/core/types.rb
|
213
217
|
- lib/trax/core/types/array.rb
|
218
|
+
- lib/trax/core/types/array_of.rb
|
219
|
+
- lib/trax/core/types/behaviors.rb
|
220
|
+
- lib/trax/core/types/behaviors/array_of_members.rb
|
214
221
|
- lib/trax/core/types/boolean.rb
|
215
222
|
- lib/trax/core/types/enum.rb
|
216
223
|
- lib/trax/core/types/enum_value.rb
|
@@ -222,7 +229,6 @@ files:
|
|
222
229
|
- lib/trax_core.rb
|
223
230
|
- lib/trax_core/version.rb
|
224
231
|
- spec/spec_helper.rb
|
225
|
-
- spec/support/category_enum.rb
|
226
232
|
- spec/support/defs.rb
|
227
233
|
- spec/support/ecom.rb
|
228
234
|
- spec/support/ecom/widget.rb
|
@@ -247,14 +253,15 @@ files:
|
|
247
253
|
- spec/trax/core/ext/module_spec.rb
|
248
254
|
- spec/trax/core/ext/object_spec.rb
|
249
255
|
- spec/trax/core/ext/uri_spec.rb
|
256
|
+
- spec/trax/core/has_dependencies_spec.rb
|
250
257
|
- spec/trax/core/has_mixins_spec.rb
|
251
258
|
- spec/trax/core/inheritance_spec.rb
|
252
259
|
- spec/trax/core/named_class_spec.rb
|
253
260
|
- spec/trax/core/named_module_spec.rb
|
261
|
+
- spec/trax/core/types/array_spec.rb
|
254
262
|
- spec/trax/core/types/enum_spec.rb
|
255
263
|
- spec/trax/core/types/struct_spec.rb
|
256
264
|
- spec/trax/core_spec.rb
|
257
|
-
- spec/trax/enum_spec.rb
|
258
265
|
- spec/trax/hash_spec.rb
|
259
266
|
- trax_core.gemspec
|
260
267
|
homepage: http://github.com/jasonayre/trax_core
|
@@ -283,7 +290,6 @@ specification_version: 4
|
|
283
290
|
summary: Core Trax Dependencies
|
284
291
|
test_files:
|
285
292
|
- spec/spec_helper.rb
|
286
|
-
- spec/support/category_enum.rb
|
287
293
|
- spec/support/defs.rb
|
288
294
|
- spec/support/ecom.rb
|
289
295
|
- spec/support/ecom/widget.rb
|
@@ -308,12 +314,13 @@ test_files:
|
|
308
314
|
- spec/trax/core/ext/module_spec.rb
|
309
315
|
- spec/trax/core/ext/object_spec.rb
|
310
316
|
- spec/trax/core/ext/uri_spec.rb
|
317
|
+
- spec/trax/core/has_dependencies_spec.rb
|
311
318
|
- spec/trax/core/has_mixins_spec.rb
|
312
319
|
- spec/trax/core/inheritance_spec.rb
|
313
320
|
- spec/trax/core/named_class_spec.rb
|
314
321
|
- spec/trax/core/named_module_spec.rb
|
322
|
+
- spec/trax/core/types/array_spec.rb
|
315
323
|
- spec/trax/core/types/enum_spec.rb
|
316
324
|
- spec/trax/core/types/struct_spec.rb
|
317
325
|
- spec/trax/core_spec.rb
|
318
|
-
- spec/trax/enum_spec.rb
|
319
326
|
- spec/trax/hash_spec.rb
|
data/spec/trax/enum_spec.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ::Enum do
|
4
|
-
subject do
|
5
|
-
::CategoryEnum
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:expected_names) { [:default, :clothing, :shoes, :accessories] }
|
9
|
-
let(:expected_values) { [1,2,3,4] }
|
10
|
-
|
11
|
-
describe ".key?" do
|
12
|
-
it { subject.key?(:default).should eq true }
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "[](val)" do
|
16
|
-
it { subject[:default].to_i.should eq 1 }
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "[](val)" do
|
20
|
-
it { subject["default"].to_i.should eq 1 }
|
21
|
-
end
|
22
|
-
|
23
|
-
describe ".value?" do
|
24
|
-
it { subject.value?(1).should eq true }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe ".keys" do
|
28
|
-
it { subject.keys.should eq [:default, :clothing, :shoes, :accessories] }
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".names" do
|
32
|
-
it { subject.keys.should eq expected_names }
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".values" do
|
36
|
-
it { subject.values.should eq expected_values }
|
37
|
-
end
|
38
|
-
|
39
|
-
context "duplicate enum name" do
|
40
|
-
it { expect{subject.define_enum_value(:default, 6)}.to raise_error(::Trax::Core::Errors::DuplicateEnumValue) }
|
41
|
-
end
|
42
|
-
|
43
|
-
context "duplicate enum value" do
|
44
|
-
it {expect{subject.define_enum_value(:newthing, 1)}.to raise_error(::Trax::Core::Errors::DuplicateEnumValue) }
|
45
|
-
end
|
46
|
-
|
47
|
-
context "InstanceMethods" do
|
48
|
-
subject { ::CategoryEnum.new(:clothing) }
|
49
|
-
|
50
|
-
it { subject.choice.should eq :clothing }
|
51
|
-
it { subject.choice.should eq 2 }
|
52
|
-
it { expect(subject.next_value.to_sym).to eq :shoes }
|
53
|
-
it { expect(subject.previous_value.to_sym).to eq :default }
|
54
|
-
|
55
|
-
context "selection of values" do
|
56
|
-
it { subject.select_next_value.should eq ::CategoryEnum.new(:shoes).choice }
|
57
|
-
end
|
58
|
-
context "value is last" do
|
59
|
-
subject { ::CategoryEnum.new(:accessories) }
|
60
|
-
it { subject.next_value?.should eq false }
|
61
|
-
it { subject.previous_value?.should eq true }
|
62
|
-
|
63
|
-
context "selection of value" do
|
64
|
-
it { expect(subject.select_next_value).to eq ::CategoryEnum.new(:accessories) }
|
65
|
-
it { expect(subject.select_previous_value).to eq ::CategoryEnum.new(:shoes) }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|