acts_as_authoritah 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -3
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +4 -2
- data/README.md +29 -0
- data/Rakefile +2 -56
- data/acts_as_authoritah.gemspec +15 -44
- data/lib/acts_as_authoritah.rb +15 -16
- data/lib/acts_as_authoritah/access_control_list.rb +32 -0
- data/lib/acts_as_authoritah/access_rule.rb +31 -0
- data/lib/acts_as_authoritah/core.rb +37 -0
- data/lib/acts_as_authoritah/identifier_parser.rb +28 -0
- data/lib/acts_as_authoritah/matchers/controller_matcher.rb +10 -0
- data/lib/acts_as_authoritah/matchers/direct_matcher.rb +9 -0
- data/lib/acts_as_authoritah/matchers/scope_matcher.rb +15 -0
- data/lib/acts_as_authoritah/spreadsheets/access_rights_mapper.rb +14 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_header_parser.rb +9 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_reader.rb +37 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_row_parser.rb +23 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_wrapper.rb +16 -0
- data/lib/acts_as_authoritah/version.rb +3 -0
- data/spec/acts_as_authoritah/access_control_list_spec.rb +78 -0
- data/spec/acts_as_authoritah/access_rule_spec.rb +39 -0
- data/spec/acts_as_authoritah/core_spec.rb +63 -0
- data/spec/acts_as_authoritah/identifier_parser_spec.rb +111 -0
- data/spec/acts_as_authoritah/matchers/controller_matcher_spec.rb +20 -0
- data/spec/acts_as_authoritah/matchers/direct_matcher_spec.rb +20 -0
- data/spec/acts_as_authoritah/matchers/scope_matcher_spec.rb +25 -0
- data/spec/acts_as_authoritah/spreadsheets/access_rights_mapper_spec.rb +13 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_header_parser_spec.rb +8 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_reader_spec.rb +29 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_row_parser_spec.rb +24 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_wrapper_spec.rb +15 -0
- data/spec/data/default.xls +0 -0
- data/spec/spec_helper.rb +5 -0
- metadata +91 -72
- data/.document +0 -5
- data/README.rdoc +0 -123
- data/VERSION +0 -1
- data/lib/access_control.rb +0 -30
- data/lib/access_rights.rb +0 -88
- data/lib/custom_exceptions.rb +0 -8
- data/lib/handler.rb +0 -38
- data/lib/loader.rb +0 -27
- data/test/acts_as_authoritah_test.rb +0 -23
- data/test/test_helper.rb +0 -22
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsAuthoritah::SpreadsheetRowParser do
|
4
|
+
before :each do
|
5
|
+
@valid_row = ["scope1::scope2", "Dummy", "edit", "test", "x", "X", nil]
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should take a valid row and return the scope" do
|
9
|
+
ActsAsAuthoritah::SpreadsheetRowParser.new(@valid_row).scope.should eq "scope1::scope2"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should take a valid row and return the controller" do
|
13
|
+
ActsAsAuthoritah::SpreadsheetRowParser.new(@valid_row).controller.should eq "Dummy"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should take a valid row and return the action" do
|
17
|
+
ActsAsAuthoritah::SpreadsheetRowParser.new(@valid_row).action.should eq "edit"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should take a valid row and return the access rights" do
|
21
|
+
ActsAsAuthoritah::SpreadsheetRowParser.new(@valid_row).access_rights.should eq [true, true, false]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsAuthoritah::SpreadsheetWrapper do
|
4
|
+
it "should be able to open a spreadsheet and convert to an array of AccessRules" do
|
5
|
+
ActsAsAuthoritah::SpreadsheetWrapper.new("spec/data/default.xls").to_access_rules.first.class.should eq ActsAsAuthoritah::AccessRule
|
6
|
+
end
|
7
|
+
|
8
|
+
it "ssadf" do
|
9
|
+
access_rules = ActsAsAuthoritah::SpreadsheetWrapper.new("spec/data/default.xls").to_access_rules
|
10
|
+
ActsAsAuthoritah::AccessControlList.new(access_rules).store.should eq({
|
11
|
+
"scope1::scope2::DummyController#edit"=>{"admin"=>true, "anonymous"=>false, "super_admin"=>true},
|
12
|
+
"scope3::scope4::AnotherController#update"=>{"admin"=>false, "anonymous"=>true, "super_admin"=>true}
|
13
|
+
})
|
14
|
+
end
|
15
|
+
end
|
Binary file
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,97 +1,116 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_authoritah
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 5
|
10
|
-
version: 1.0.5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
- BangTheTable
|
7
|
+
authors:
|
14
8
|
- Unnikrishnan KP
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
date: 2012-04-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2151808300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
24
23
|
prerelease: false
|
25
|
-
|
24
|
+
version_requirements: *2151808300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &2151807780 !ruby/object:Gem::Requirement
|
26
28
|
none: false
|
27
|
-
requirements:
|
28
|
-
- -
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
email: devteam@bangthetable.com, unni.tallman@gmail.com
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2151807780
|
36
|
+
description: Define user capabilities in your app
|
37
|
+
email:
|
38
|
+
- unni.tallman@gmail.com
|
38
39
|
executables: []
|
39
|
-
|
40
40
|
extensions: []
|
41
|
-
|
42
|
-
|
43
|
-
- LICENSE
|
44
|
-
- README.rdoc
|
45
|
-
files:
|
46
|
-
- .document
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
47
43
|
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- Gemfile
|
48
46
|
- LICENSE
|
49
|
-
- README.
|
47
|
+
- README.md
|
50
48
|
- Rakefile
|
51
|
-
- VERSION
|
52
49
|
- acts_as_authoritah.gemspec
|
53
50
|
- lib/acts_as_authoritah.rb
|
54
|
-
- lib/
|
55
|
-
- lib/
|
56
|
-
- lib/
|
57
|
-
- lib/
|
58
|
-
- lib/
|
59
|
-
-
|
60
|
-
-
|
61
|
-
|
62
|
-
|
51
|
+
- lib/acts_as_authoritah/access_control_list.rb
|
52
|
+
- lib/acts_as_authoritah/access_rule.rb
|
53
|
+
- lib/acts_as_authoritah/core.rb
|
54
|
+
- lib/acts_as_authoritah/identifier_parser.rb
|
55
|
+
- lib/acts_as_authoritah/matchers/controller_matcher.rb
|
56
|
+
- lib/acts_as_authoritah/matchers/direct_matcher.rb
|
57
|
+
- lib/acts_as_authoritah/matchers/scope_matcher.rb
|
58
|
+
- lib/acts_as_authoritah/spreadsheets/access_rights_mapper.rb
|
59
|
+
- lib/acts_as_authoritah/spreadsheets/spreadsheet_header_parser.rb
|
60
|
+
- lib/acts_as_authoritah/spreadsheets/spreadsheet_reader.rb
|
61
|
+
- lib/acts_as_authoritah/spreadsheets/spreadsheet_row_parser.rb
|
62
|
+
- lib/acts_as_authoritah/spreadsheets/spreadsheet_wrapper.rb
|
63
|
+
- lib/acts_as_authoritah/version.rb
|
64
|
+
- spec/acts_as_authoritah/access_control_list_spec.rb
|
65
|
+
- spec/acts_as_authoritah/access_rule_spec.rb
|
66
|
+
- spec/acts_as_authoritah/core_spec.rb
|
67
|
+
- spec/acts_as_authoritah/identifier_parser_spec.rb
|
68
|
+
- spec/acts_as_authoritah/matchers/controller_matcher_spec.rb
|
69
|
+
- spec/acts_as_authoritah/matchers/direct_matcher_spec.rb
|
70
|
+
- spec/acts_as_authoritah/matchers/scope_matcher_spec.rb
|
71
|
+
- spec/acts_as_authoritah/spreadsheets/access_rights_mapper_spec.rb
|
72
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_header_parser_spec.rb
|
73
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_reader_spec.rb
|
74
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_row_parser_spec.rb
|
75
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_wrapper_spec.rb
|
76
|
+
- spec/data/default.xls
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: ''
|
63
79
|
licenses: []
|
64
|
-
|
65
80
|
post_install_message:
|
66
|
-
rdoc_options:
|
67
|
-
|
68
|
-
require_paths:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
69
83
|
- lib
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
85
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
|
77
|
-
- 0
|
78
|
-
version: "0"
|
79
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
91
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
version: "0"
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
88
96
|
requirements: []
|
89
|
-
|
90
97
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
98
|
+
rubygems_version: 1.8.17
|
92
99
|
signing_key:
|
93
100
|
specification_version: 3
|
94
|
-
summary:
|
95
|
-
test_files:
|
96
|
-
-
|
97
|
-
-
|
101
|
+
summary: Define user capabilities in your app
|
102
|
+
test_files:
|
103
|
+
- spec/acts_as_authoritah/access_control_list_spec.rb
|
104
|
+
- spec/acts_as_authoritah/access_rule_spec.rb
|
105
|
+
- spec/acts_as_authoritah/core_spec.rb
|
106
|
+
- spec/acts_as_authoritah/identifier_parser_spec.rb
|
107
|
+
- spec/acts_as_authoritah/matchers/controller_matcher_spec.rb
|
108
|
+
- spec/acts_as_authoritah/matchers/direct_matcher_spec.rb
|
109
|
+
- spec/acts_as_authoritah/matchers/scope_matcher_spec.rb
|
110
|
+
- spec/acts_as_authoritah/spreadsheets/access_rights_mapper_spec.rb
|
111
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_header_parser_spec.rb
|
112
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_reader_spec.rb
|
113
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_row_parser_spec.rb
|
114
|
+
- spec/acts_as_authoritah/spreadsheets/spreadsheet_wrapper_spec.rb
|
115
|
+
- spec/data/default.xls
|
116
|
+
- spec/spec_helper.rb
|
data/.document
DELETED
data/README.rdoc
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
= acts_as_authoritah
|
2
|
-
|
3
|
-
INSTALLATION
|
4
|
-
|
5
|
-
gem install acts_as_authoritah
|
6
|
-
|
7
|
-
Rails 2.*
|
8
|
-
Add in environemnt.rb
|
9
|
-
config.gem 'acts_as_authoritah'
|
10
|
-
|
11
|
-
Rails 3.*
|
12
|
-
Add in Gemfile
|
13
|
-
gem 'acts_as_authoritah'
|
14
|
-
|
15
|
-
= A sample blogging app.
|
16
|
-
|
17
|
-
- Creating blog posts.
|
18
|
-
- Editing blog posts.
|
19
|
-
- Commenting on blog posts.
|
20
|
-
|
21
|
-
A blog post when first created will be in unpublished state. The post can be published later.
|
22
|
-
|
23
|
-
User Roles and capabilities.
|
24
|
-
|
25
|
-
- Author
|
26
|
-
He can create blog posts
|
27
|
-
He can edit posts
|
28
|
-
He can view blog posts
|
29
|
-
He cannot add comments
|
30
|
-
- Registered user (who has signed up and logged-in)
|
31
|
-
He can view blog posts
|
32
|
-
He can comment on blog posts
|
33
|
-
He cannot create blog posts
|
34
|
-
He cannot edit blog posts
|
35
|
-
- anonymous user
|
36
|
-
He can view blog posts
|
37
|
-
He cannot add comments
|
38
|
-
He cannot create blog posts
|
39
|
-
He cannot edit blog posts
|
40
|
-
- admin
|
41
|
-
unrestricted access to everything.
|
42
|
-
|
43
|
-
|
44
|
-
When post is unpublished
|
45
|
-
|
46
|
-
- Logged-in user (who has signed up)
|
47
|
-
He cannot comment on blog posts
|
48
|
-
He cannot view blog posts.
|
49
|
-
|
50
|
-
|
51
|
-
= Getting this done with ActsAsAuthoritah
|
52
|
-
|
53
|
-
1. Create an excel sheet (or download a sample https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/default.xls)
|
54
|
-
and save it at config/acl/default.xls. When the post is unpublished, there are two rules which are different from the default set of rules.
|
55
|
-
We need to add these two rules alone in config/acl/unpublished.xls https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/unpublished.xls
|
56
|
-
|
57
|
-
2. Add the following line to your User model (or to whichever is your equivalent of User model)
|
58
|
-
|
59
|
-
acts_as_authoritah :acl_folder => File.join(RAILS_ROOT,"config","acl")
|
60
|
-
|
61
|
-
3. Add 'include ActsAsAuthoritah' in ApplicationController
|
62
|
-
|
63
|
-
4. ActsAsAuthoritah needs a wrapper around your 'current_user' method (name may differ based on the authentication system you use), to make it return an empty User object when
|
64
|
-
user is not logged in.
|
65
|
-
|
66
|
-
A sample -
|
67
|
-
|
68
|
-
def present_user
|
69
|
-
current_user.to_s == "false" ? User.new : current_user
|
70
|
-
end
|
71
|
-
|
72
|
-
5. In your User model, you need to define a 'usertype' method which should return the role of that user (same as in the first row of the spreadsheet).
|
73
|
-
|
74
|
-
A sample -
|
75
|
-
|
76
|
-
def usertype(args={})
|
77
|
-
return role.name if role
|
78
|
-
return "anonymous" if new_record?
|
79
|
-
return "registered"
|
80
|
-
end
|
81
|
-
|
82
|
-
Implementation of usertype method can vary, based on the role-system you are following. Just make sure it always returns role of the user (string), which should match with the roles
|
83
|
-
specified in the first row of the spreadsheet.
|
84
|
-
|
85
|
-
|
86
|
-
6. in Post model
|
87
|
-
|
88
|
-
def status
|
89
|
-
published? ? nil : 'unpublished'
|
90
|
-
end
|
91
|
-
|
92
|
-
This will be used to let authoritah know when a post in in unpublished state, so that authoritah can override the default rules with those in unpublished.xls
|
93
|
-
|
94
|
-
7. For access control of methods in PostController and CommentController, put these two files in lib/access_control/
|
95
|
-
https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/comment_controller_access.rb
|
96
|
-
https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/post_controller_access.rb
|
97
|
-
|
98
|
-
8. To make sure that links are shown only to appropriate users, add lines like these in in the views.
|
99
|
-
|
100
|
-
<% if present_user.can_post_a_comment?(:context => @post.status) %>
|
101
|
-
<%= link_to 'Add a comment', {:controller => 'comment', :action => 'new', :post_id => @post.id} %>
|
102
|
-
<% end%>
|
103
|
-
|
104
|
-
9. Thats all - your application is access controlled by ActsAsAuthoritah now.
|
105
|
-
|
106
|
-
- You can grant/revoke access to different features to different roles just by editing the spreadsheets.
|
107
|
-
- You can add a new user-role by adding a column in the spreadsheets.
|
108
|
-
- If your application needs to have one more context (say, archived posts), you can do that by adding one more spreadsheet called archived.xls.
|
109
|
-
|
110
|
-
== Note on Patches/Pull Requests
|
111
|
-
|
112
|
-
* Fork the project.
|
113
|
-
* Make your feature addition or bug fix.
|
114
|
-
* Add tests for it. This is important so I don't break it in a
|
115
|
-
future version unintentionally.
|
116
|
-
* Commit, do not mess with rakefile, version, or history.
|
117
|
-
(if you want to have your own version, that is fine but
|
118
|
-
bump version in a commit by itself I can ignore when I pull)
|
119
|
-
* Send me a pull request. Bonus points for topic branches.
|
120
|
-
|
121
|
-
== Copyright
|
122
|
-
|
123
|
-
Copyright (c) 2010 Bang The Table. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.1
|
data/lib/access_control.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
Dir[File.join(Dir.pwd,'lib','access_control','*.rb')].each {|f| require f}
|
2
|
-
|
3
|
-
module AccessControls
|
4
|
-
def self.access_control(controller)
|
5
|
-
params = controller.params
|
6
|
-
access_control_method = params[:action]
|
7
|
-
begin
|
8
|
-
access_module = (controller.class.to_s + "Access").constantize
|
9
|
-
rescue => e
|
10
|
-
if e.to_s =~ /uninitialized constant/
|
11
|
-
Rails.logger.info "\nAccess control module for #{controller.class.to_s} is not defined yet\n"
|
12
|
-
return true
|
13
|
-
else
|
14
|
-
raise
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
begin
|
19
|
-
return access_module.send(access_control_method,controller)
|
20
|
-
rescue => e
|
21
|
-
if e.to_s =~ /undefined method/
|
22
|
-
Rails.logger.info "#{e.to_s}\nAccess control method '#{access_control_method}' is not defined yet in " +
|
23
|
-
controller.class.to_s + "Access" + "module\n"
|
24
|
-
return true
|
25
|
-
else
|
26
|
-
raise
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/access_rights.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
module ActsAsAuthoritah
|
2
|
-
def deny_unauthorized_access
|
3
|
-
if File.exists?("#{Rails.public_path}/401.html") and !request.xhr?
|
4
|
-
render :file => "#{Rails.public_path}/401.html", :status => :unauthorized and return
|
5
|
-
else
|
6
|
-
render :text => "access denied", :status => :unauthorized and return
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module AccessRights
|
11
|
-
ACL = Hash.new
|
12
|
-
Default = Hash.new
|
13
|
-
Urls = {}
|
14
|
-
|
15
|
-
def self.feature_list
|
16
|
-
Default.keys.collect(&:downcase)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.urls(context)
|
20
|
-
h = {}
|
21
|
-
ACL[context].keys.collect(&:downcase).each do |feature|
|
22
|
-
h[feature] = access_url(feature)
|
23
|
-
end
|
24
|
-
h
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.access_url(feature)
|
28
|
-
Urls[feature.downcase]
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.contexts
|
32
|
-
ACL.keys.collect(&:downcase)
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.load_all_files(dir,default_file="default.xls")
|
36
|
-
Dir.xls_files(dir).each do |file|
|
37
|
-
acl_type = file.split(".").first
|
38
|
-
ACL[acl_type] = load(File.join(dir,file))
|
39
|
-
end
|
40
|
-
|
41
|
-
(ACL[default_file.split(".").first] || {}).each_pair do |key,value|
|
42
|
-
Default[key] = value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.load(file)
|
47
|
-
hash = {}
|
48
|
-
book = Spreadsheet.open file
|
49
|
-
sheet = book.worksheets.first
|
50
|
-
|
51
|
-
urls_column_index = -1
|
52
|
-
|
53
|
-
usertypes = []
|
54
|
-
|
55
|
-
sheet.each do |row|
|
56
|
-
if row[0] == 'name'
|
57
|
-
k = 2
|
58
|
-
while true
|
59
|
-
usertype = row[k]
|
60
|
-
break unless usertype
|
61
|
-
|
62
|
-
usertypes << usertype unless usertype.downcase == "url"
|
63
|
-
urls_column_index = k if usertype.downcase == "url"
|
64
|
-
|
65
|
-
k += 1
|
66
|
-
end
|
67
|
-
usertypes = usertypes.collect(&:downcase)
|
68
|
-
next
|
69
|
-
end
|
70
|
-
|
71
|
-
h = Hash.new
|
72
|
-
feature_name = row[0]
|
73
|
-
|
74
|
-
next unless feature_name
|
75
|
-
feature_name.strip!
|
76
|
-
|
77
|
-
Urls[feature_name] = row[urls_column_index] unless urls_column_index == -1
|
78
|
-
|
79
|
-
usertypes.each_with_index do |key,i|
|
80
|
-
value = (row[i+2] and row[i+2].include?('x')) ? true : false
|
81
|
-
h[key]=value
|
82
|
-
end
|
83
|
-
hash[feature_name] = h
|
84
|
-
end
|
85
|
-
return hash
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|