troles 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.textile +75 -16
- data/VERSION +1 -1
- data/lib/trole/adapters/active_record/config.rb +3 -3
- data/lib/trole/adapters/mongoid/config.rb +5 -5
- data/lib/trole/config.rb +2 -2
- data/lib/trole_groups.rb +10 -0
- data/lib/trole_groups/READ THIS.textile +4 -0
- data/lib/trole_groups/Rolegroups design.textile +218 -0
- data/lib/trole_groups/adapters/active_record.rb +8 -0
- data/lib/trole_groups/adapters/active_record/config.rb +0 -0
- data/lib/trole_groups/adapters/active_record/storage.rb +0 -0
- data/lib/trole_groups/adapters/active_record/strategy.rb +11 -0
- data/lib/trole_groups/adapters/mongoid.rb +8 -0
- data/lib/trole_groups/adapters/mongoid/config.rb +0 -0
- data/lib/trole_groups/api.rb +29 -0
- data/lib/trole_groups/api/cache.rb +13 -0
- data/lib/trole_groups/api/config.rb +4 -0
- data/lib/trole_groups/api/core.rb +50 -0
- data/lib/trole_groups/api/event.rb +29 -0
- data/lib/trole_groups/api/read.rb +56 -0
- data/lib/trole_groups/api/validation.rb +44 -0
- data/lib/trole_groups/api/write.rb +60 -0
- data/lib/trole_groups/config.rb +134 -0
- data/lib/trole_groups/config/schema.rb +65 -0
- data/lib/trole_groups/config/schema/helpers.rb +11 -0
- data/lib/trole_groups/config/schema/role_group_helpers.rb +11 -0
- data/lib/trole_groups/config/valid_role_groups.rb +21 -0
- data/lib/trole_groups/macros.rb +42 -0
- data/lib/trole_groups/macros/configuration.rb +89 -0
- data/lib/trole_groups/macros/configuration/base_loader.rb +35 -0
- data/lib/trole_groups/macros/configuration/config_loader.rb +19 -0
- data/lib/trole_groups/macros/configuration/storage_loader.rb +20 -0
- data/lib/trole_groups/macros/configuration/strategy_loader.rb +38 -0
- data/lib/trole_groups/macros/static_roles.rb +9 -0
- data/lib/trole_groups/macros/strategy_options.rb +21 -0
- data/lib/trole_groups/operations.rb +25 -0
- data/lib/trole_groups/operations/read.rb +36 -0
- data/lib/trole_groups/operations/write.rb +42 -0
- data/lib/trole_groups/storage.rb +27 -0
- data/lib/trole_groups/storage/base_many.rb +93 -0
- data/lib/trole_groups/storage/embed_many.rb +58 -0
- data/lib/trole_groups/storage/ref_many.rb +47 -0
- data/lib/trole_groups/strategy.rb +30 -0
- data/lib/troles/adapters/active_record/config.rb +32 -9
- data/lib/troles/adapters/mongoid/config.rb +7 -7
- data/lib/troles/common/api/core.rb +1 -1
- data/lib/troles/common/config.rb +49 -14
- data/lib/troles/common/config/schema.rb +17 -23
- data/lib/troles/common/config/schema/helpers.rb +77 -0
- data/lib/troles/common/config/schema/role_helpers.rb +27 -0
- data/lib/troles/common/config/static_roles.rb +4 -4
- data/lib/troles/common/macros.rb +4 -4
- data/lib/troles/common/macros/configuration.rb +8 -8
- data/lib/troles/common/macros/strategy_options.rb +4 -4
- data/lib/troles/common/storage.rb +1 -0
- data/lib/troles/config.rb +2 -2
- data/lib/troles/storage/ref_many.rb +2 -3
- data/spec/active_record/models/ref_many.rb +3 -0
- data/spec/active_record/strategies/many/ref_many_spec.rb +2 -1
- data/spec/generic/models/role.rb +2 -1
- data/spec/trole_groups/api/core_api_spec.rb +14 -0
- data/spec/trole_groups/api/read_api_spec.rb +36 -0
- data/spec/trole_groups/api/write_api_spec.rb +19 -0
- data/spec/trole_groups/api_spec.rb +27 -0
- data/spec/trole_groups/generic/models.rb +3 -0
- data/spec/trole_groups/generic/models/role_group.rb +44 -0
- data/spec/trole_groups/generic/models/user.rb +9 -0
- data/spec/trole_groups/strategies/ref_many.rb +51 -0
- data/spec/trole_groups/strategy_helper.rb +9 -0
- data/spec/trole_groups_spec.rb +11 -0
- data/spec/trole_spec_helper.rb +9 -0
- data/spec/troles/api_spec.rb +12 -18
- data/troles.gemspec +52 -4
- metadata +85 -37
- data/development.sqlite3 +0 -0
- data/lib/troles/common/config/schema_helpers.rb +0 -95
data/development.sqlite3
DELETED
Binary file
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module Troles::Common
|
2
|
-
class Config
|
3
|
-
module SchemaHelpers
|
4
|
-
def valid_field_name? name
|
5
|
-
return false if !name || name.empty?
|
6
|
-
raise ArgumentException, "Role field must not be named role or roles as these names are reserved by troles!" if [:role, :roles].include? name.to_sym
|
7
|
-
true
|
8
|
-
end
|
9
|
-
|
10
|
-
def boolean? value
|
11
|
-
[true, false].include? value
|
12
|
-
end
|
13
|
-
|
14
|
-
# TODO: Needs extraction into helper module!
|
15
|
-
|
16
|
-
def belongs_to_for from, to, options = {}
|
17
|
-
make_relationship :belongs_to, from, to, options
|
18
|
-
end
|
19
|
-
|
20
|
-
def has_many_for from, to, options = {}
|
21
|
-
make_relationship :has_many, from, to, options
|
22
|
-
end
|
23
|
-
|
24
|
-
def has_one_for from, to, options = {}
|
25
|
-
make_relationship :has_one, from, to, options
|
26
|
-
end
|
27
|
-
|
28
|
-
# To setup sth like this:
|
29
|
-
#
|
30
|
-
# class UserAccount < ActiveRecord::Base
|
31
|
-
# has_and_belongs_to_many :troles, :class_name => 'Role'
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# class Role < ActiveRecord::Base
|
35
|
-
# has_and_belongs_to_many :user_accounts, :class_name => 'User'
|
36
|
-
# end
|
37
|
-
def has_and_belongs_many from, to, options = {}
|
38
|
-
make_relationship :has_and_belongs_to_many, from, to, :key => role_field
|
39
|
-
make_relationship :has_and_belongs_to_many, to, from, options
|
40
|
-
end
|
41
|
-
|
42
|
-
def get_model_type class_name
|
43
|
-
return :user if class_name == clazz
|
44
|
-
return :role if class_name == role_model
|
45
|
-
raise "Not a known model: #{class_name}"
|
46
|
-
end
|
47
|
-
|
48
|
-
# options:
|
49
|
-
# - :opts, extras options, fx to set the :through relationship
|
50
|
-
# - :key (usually to enforce use of role_field as key name)
|
51
|
-
def make_relationship type, from, to, options = {}
|
52
|
-
# puts "type: #{type}, #{from}, #{to}"
|
53
|
-
from_type = get_model_type from
|
54
|
-
to_type = get_model_type to
|
55
|
-
|
56
|
-
model_key = options[:key] ? options[:key] : send("#{from_type}_key")
|
57
|
-
|
58
|
-
class_name = send "#{to_type}_class_name"
|
59
|
-
|
60
|
-
options = {:class_name => class_name}
|
61
|
-
options.merge!(options[:opts]) if options[:opts]
|
62
|
-
puts "#{from}.#{type} :#{model_key}, #{options.inspect}" if log_on?
|
63
|
-
from.send(type, model_key, options)
|
64
|
-
end
|
65
|
-
|
66
|
-
def user_class_name
|
67
|
-
clazz.to_s
|
68
|
-
end
|
69
|
-
|
70
|
-
def user_key
|
71
|
-
make_key user_class_name
|
72
|
-
end
|
73
|
-
|
74
|
-
def join_class_name
|
75
|
-
join_model.to_s
|
76
|
-
end
|
77
|
-
|
78
|
-
def join_key
|
79
|
-
make_key join_class_name
|
80
|
-
end
|
81
|
-
|
82
|
-
def role_class_name
|
83
|
-
role_model.to_s
|
84
|
-
end
|
85
|
-
|
86
|
-
def role_key
|
87
|
-
make_key role_class_name
|
88
|
-
end
|
89
|
-
|
90
|
-
def make_key name
|
91
|
-
name.gsub(/::/, '__').underscore.pluralize
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|