tin_opener 0.0.1
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.
- checksums.yaml +7 -0
- data/LICENSE +662 -0
- data/README.md +37 -0
- data/Rakefile +33 -0
- data/app/assets/javascripts/tin_opener/application.js +13 -0
- data/app/assets/stylesheets/tin_opener/application.css +15 -0
- data/app/controllers/tin_opener/application_controller.rb +4 -0
- data/app/controllers/tin_opener/data_sets_controller.rb +51 -0
- data/app/controllers/tin_opener/records_controller.rb +62 -0
- data/app/helpers/tin_opener/application_helper.rb +4 -0
- data/app/models/tin_opener/data_set.rb +39 -0
- data/app/models/tin_opener/record.rb +8 -0
- data/app/views/layouts/tin_opener/application.html.erb +14 -0
- data/app/views/tin_opener/data_sets/_form.html.erb +25 -0
- data/app/views/tin_opener/data_sets/edit.html.erb +6 -0
- data/app/views/tin_opener/data_sets/index.html.erb +29 -0
- data/app/views/tin_opener/data_sets/show.html.erb +19 -0
- data/app/views/tin_opener/records/_form.html.erb +24 -0
- data/app/views/tin_opener/records/_record.html.erb +8 -0
- data/app/views/tin_opener/records/edit.html.erb +6 -0
- data/app/views/tin_opener/records/index.html.erb +25 -0
- data/app/views/tin_opener/records/new.html.erb +5 -0
- data/app/views/tin_opener/records/show.html.erb +11 -0
- data/config/routes.rb +7 -0
- data/config/spring.rb +1 -0
- data/db/migrate/20151024183112_enable_hstore.rb +5 -0
- data/db/migrate/20151024183219_create_tin_opener_data_sets.rb +10 -0
- data/db/migrate/20151024194928_create_tin_opener_records.rb +10 -0
- data/lib/tasks/tin_opener_tasks.rake +4 -0
- data/lib/tin_opener/data_file_processor.rb +22 -0
- data/lib/tin_opener/engine.rb +21 -0
- data/lib/tin_opener/version.rb +3 -0
- data/lib/tin_opener.rb +8 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +8 -0
- data/spec/dummy/bin/rake +8 -0
- data/spec/dummy/bin/rspec +7 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/bin/spring +15 -0
- data/spec/dummy/config/application.rb +31 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +18 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +34 -0
- data/spec/dummy/log/development.log +205 -0
- data/spec/dummy/log/test.log +812 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/examples.txt +7 -0
- data/spec/factories/tin_opener_data_sets.rb +6 -0
- data/spec/factories/tin_opener_records.rb +6 -0
- data/spec/fixtures/data_sets/bici_disponibilidad.csv +71 -0
- data/spec/models/tin_opener/data_set_spec.rb +24 -0
- data/spec/models/tin_opener/record_spec.rb +10 -0
- data/spec/rails_helper.rb +68 -0
- data/spec/spec_helper.rb +93 -0
- metadata +324 -0
data/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# tin_opener
|
|
2
|
+
[](https://travis-ci.org/dgilperez/tin_opener)
|
|
3
|
+
[](https://codeclimate.com/github/dgilperez/tin_opener)
|
|
4
|
+
|
|
5
|
+
Opening Data, one Tin at a time.
|
|
6
|
+
|
|
7
|
+
Rails Engine developed in the context of the Ayuntamiento de Madrid's Open Data project [https://twitter.com/hashtag/openmad](#OpenMad).
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Add gem to `Gemfile`:
|
|
12
|
+
|
|
13
|
+
gem 'tin_opener', github: 'dgilperez/tin_opener'
|
|
14
|
+
|
|
15
|
+
Add a mounting point to your `routes.rb`
|
|
16
|
+
|
|
17
|
+
mount TinOpener::Engine => "/tin_opener"
|
|
18
|
+
|
|
19
|
+
Run migrations:
|
|
20
|
+
|
|
21
|
+
rake tin_opener:install:migrations
|
|
22
|
+
rake db:migrate
|
|
23
|
+
|
|
24
|
+
This gem provides the following models:
|
|
25
|
+
|
|
26
|
+
* `TinOpener::DataSet` is any type of data structure you declare in your data domain. It's defined by it's name and headers, which in turn is a hash of key name and data type pairs.
|
|
27
|
+
* `TinOpener::Record` is a instance of data belonging to a DataSet format, extracted from any CSV form.
|
|
28
|
+
|
|
29
|
+
Data input format support:
|
|
30
|
+
|
|
31
|
+
* CSV
|
|
32
|
+
|
|
33
|
+
## TODO
|
|
34
|
+
|
|
35
|
+
Support for more data formats:
|
|
36
|
+
|
|
37
|
+
* Excel
|
data/Rakefile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# require 'rdoc/task'
|
|
9
|
+
#
|
|
10
|
+
# RDoc::Task.new(:rdoc) do |rdoc|
|
|
11
|
+
# rdoc.rdoc_dir = 'rdoc'
|
|
12
|
+
# rdoc.title = 'TinOpener'
|
|
13
|
+
# rdoc.options << '--line-numbers'
|
|
14
|
+
# rdoc.rdoc_files.include('README.rdoc')
|
|
15
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
|
16
|
+
# end
|
|
17
|
+
|
|
18
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
19
|
+
load 'rails/tasks/engine.rake'
|
|
20
|
+
|
|
21
|
+
load 'rails/tasks/statistics.rake'
|
|
22
|
+
|
|
23
|
+
Bundler::GemHelper.install_tasks
|
|
24
|
+
|
|
25
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
|
26
|
+
|
|
27
|
+
require 'rspec/core'
|
|
28
|
+
require 'rspec/core/rake_task'
|
|
29
|
+
|
|
30
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
|
31
|
+
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
|
|
32
|
+
|
|
33
|
+
task default: :spec
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require_dependency "tin_opener/application_controller"
|
|
2
|
+
|
|
3
|
+
module TinOpener
|
|
4
|
+
class DataSetsController < ApplicationController
|
|
5
|
+
before_action :set_data_set, only: [:show, :edit, :update, :destroy]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@data_sets = DataSet.all
|
|
9
|
+
@data_set = DataSet.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show
|
|
13
|
+
@records = @data_set.records
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def edit
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create
|
|
20
|
+
@data_set = DataSet.new(data_set_params)
|
|
21
|
+
|
|
22
|
+
if @data_set.save
|
|
23
|
+
redirect_to @data_set, notice: 'Data set was successfully created.'
|
|
24
|
+
else
|
|
25
|
+
render :new
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update
|
|
30
|
+
if @data_set.update(data_set_params)
|
|
31
|
+
redirect_to @data_set, notice: 'Data set was successfully updated.'
|
|
32
|
+
else
|
|
33
|
+
render :edit
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def destroy
|
|
38
|
+
@data_set.destroy
|
|
39
|
+
redirect_to data_sets_url, notice: 'Data set was successfully destroyed.'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
def set_data_set
|
|
44
|
+
@data_set = DataSet.find(params[:id])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def data_set_params
|
|
48
|
+
params.require(:data_set).permit(:name, :headers, :data_file)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require_dependency "tin_opener/application_controller"
|
|
2
|
+
|
|
3
|
+
module TinOpener
|
|
4
|
+
class RecordsController < ApplicationController
|
|
5
|
+
before_action :set_data_set
|
|
6
|
+
before_action :set_record, only: [:show, :edit, :update, :destroy]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@records = @data_set.records
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new
|
|
16
|
+
@record = @data_set.records.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def edit
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create
|
|
23
|
+
@record = @data_set.records.new(record_params)
|
|
24
|
+
|
|
25
|
+
if @record.save
|
|
26
|
+
redirect_to data_set_record_url(@data_set, @record), notice: 'Record was successfully created.'
|
|
27
|
+
else
|
|
28
|
+
render :new
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update
|
|
33
|
+
if @record.update(record_params)
|
|
34
|
+
redirect_to data_set_record_url(@data_set, @record), notice: 'Record was successfully updated.'
|
|
35
|
+
else
|
|
36
|
+
render :edit
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def destroy
|
|
41
|
+
@record.destroy
|
|
42
|
+
redirect_to data_set_records_url(@data_set), notice: 'Record was successfully destroyed.'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
def set_data_set
|
|
47
|
+
@data_set = DataSet.find(params[:data_set_id])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def set_record
|
|
51
|
+
@record = @data_set.records.find(params[:id])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def record_params
|
|
55
|
+
row_data = params[:record].delete(:row_data)
|
|
56
|
+
# ActionController::Parameters.new(record: { row_data: row_data })
|
|
57
|
+
params[:record].permit!.tap do |whitelisted|
|
|
58
|
+
whitelisted[:row_data] = row_data
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module TinOpener
|
|
2
|
+
class DataSet < ActiveRecord::Base
|
|
3
|
+
has_many :records, dependent: :destroy
|
|
4
|
+
|
|
5
|
+
attr_reader :data_file
|
|
6
|
+
|
|
7
|
+
validates :name, presence: true, uniqueness: { scope: :headers }
|
|
8
|
+
validates :headers, presence: true
|
|
9
|
+
|
|
10
|
+
before_validation :process_data_file
|
|
11
|
+
|
|
12
|
+
def data_file=(data_file)
|
|
13
|
+
@data_file = data_file.respond_to?(:tempfile) ? data_file.tempfile : data_file
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def process_data_file
|
|
19
|
+
return unless data_file.is_a?(File)
|
|
20
|
+
|
|
21
|
+
data_file_processor = DataFileProcessor.new(file: data_file)
|
|
22
|
+
|
|
23
|
+
self.headers = data_file_processor.headers
|
|
24
|
+
|
|
25
|
+
import_records(data_file_processor.rows)
|
|
26
|
+
# data_file_processor.rows.each do |row|
|
|
27
|
+
# records.new(row_data: row)
|
|
28
|
+
# end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def import_records(record_attrs)
|
|
32
|
+
to_import = record_attrs.map do |row|
|
|
33
|
+
records.new(row_data: row)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Record.import to_import
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>TinOpener</title>
|
|
5
|
+
<%= stylesheet_link_tag "tin_opener/application", media: "all" %>
|
|
6
|
+
<%= javascript_include_tag "tin_opener/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<%= form_for(@data_set, multipart: true) do |f| %>
|
|
2
|
+
<% if @data_set.errors.any? %>
|
|
3
|
+
<div id="error_explanation">
|
|
4
|
+
<h2><%= pluralize(@data_set.errors.count, "error") %> prohibited this data_set from being saved:</h2>
|
|
5
|
+
|
|
6
|
+
<ul>
|
|
7
|
+
<% @data_set.errors.full_messages.each do |message| %>
|
|
8
|
+
<li><%= message %></li>
|
|
9
|
+
<% end %>
|
|
10
|
+
</ul>
|
|
11
|
+
</div>
|
|
12
|
+
<% end %>
|
|
13
|
+
|
|
14
|
+
<div class="actions">
|
|
15
|
+
<div>
|
|
16
|
+
<%= f.text_field :name %>
|
|
17
|
+
</div>
|
|
18
|
+
<div>
|
|
19
|
+
<% if @data_set.new_record? %>
|
|
20
|
+
<%= f.file_field :data_file %>
|
|
21
|
+
<% end %>
|
|
22
|
+
</div>
|
|
23
|
+
<%= f.submit %>
|
|
24
|
+
</div>
|
|
25
|
+
<% end %>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
|
2
|
+
|
|
3
|
+
<h1>Listing Data Sets</h1>
|
|
4
|
+
|
|
5
|
+
<table>
|
|
6
|
+
<thead>
|
|
7
|
+
<tr>
|
|
8
|
+
<th colspan="3"></th>
|
|
9
|
+
</tr>
|
|
10
|
+
</thead>
|
|
11
|
+
|
|
12
|
+
<tbody>
|
|
13
|
+
<% @data_sets.each do |data_set| %>
|
|
14
|
+
<tr>
|
|
15
|
+
<td><%= data_set.name %></td>
|
|
16
|
+
<td><%= link_to 'Show', data_set %></td>
|
|
17
|
+
<td><%= link_to 'Edit', edit_data_set_path(data_set) %></td>
|
|
18
|
+
<td><%= link_to 'Add more records', new_data_set_record_path(data_set) %></td>
|
|
19
|
+
<td><%= button_to 'Destroy', data_set, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
|
20
|
+
</tr>
|
|
21
|
+
<% end %>
|
|
22
|
+
</tbody>
|
|
23
|
+
</table>
|
|
24
|
+
|
|
25
|
+
<br>
|
|
26
|
+
|
|
27
|
+
New Data Set
|
|
28
|
+
|
|
29
|
+
<%= render 'form' %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
|
2
|
+
|
|
3
|
+
<%= link_to 'Edit', edit_data_set_path(@data_set) %> |
|
|
4
|
+
<%= link_to 'Back', data_sets_path %>
|
|
5
|
+
|
|
6
|
+
<h1><%= @data_set.name %></h1>
|
|
7
|
+
|
|
8
|
+
<h2>Structure</h2>
|
|
9
|
+
<p>
|
|
10
|
+
<%= @data_set.headers.keys.join(', ') %>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<h2>Records</h2>
|
|
14
|
+
|
|
15
|
+
<% if @records.present? %>
|
|
16
|
+
<%= render @records %>
|
|
17
|
+
<% else %>
|
|
18
|
+
<p>No records added for this data set yet.</p>
|
|
19
|
+
<% end %>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%= form_for([@data_set, @record]) do |f| %>
|
|
2
|
+
<% if @record.errors.any? %>
|
|
3
|
+
<div id="error_explanation">
|
|
4
|
+
<h2><%= pluralize(@record.errors.count, "error") %> prohibited this record from being saved:</h2>
|
|
5
|
+
|
|
6
|
+
<ul>
|
|
7
|
+
<% @record.errors.full_messages.each do |message| %>
|
|
8
|
+
<li><%= message %></li>
|
|
9
|
+
<% end %>
|
|
10
|
+
</ul>
|
|
11
|
+
</div>
|
|
12
|
+
<% end %>
|
|
13
|
+
|
|
14
|
+
<div class="actions">
|
|
15
|
+
<%= f.fields_for :row_data do |header_fields| %>
|
|
16
|
+
<% @data_set.headers.each do |key, _| %>
|
|
17
|
+
<div>
|
|
18
|
+
<%= header_fields.text_field key, value: @record.row_data.try{ |h| h[key] } %>
|
|
19
|
+
</div>
|
|
20
|
+
<% end %>
|
|
21
|
+
<% end %>
|
|
22
|
+
<%= f.submit %>
|
|
23
|
+
</div>
|
|
24
|
+
<% end %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
|
2
|
+
|
|
3
|
+
<h1>Listing Records</h1>
|
|
4
|
+
|
|
5
|
+
<table>
|
|
6
|
+
<thead>
|
|
7
|
+
<tr>
|
|
8
|
+
<th colspan="3"></th>
|
|
9
|
+
</tr>
|
|
10
|
+
</thead>
|
|
11
|
+
|
|
12
|
+
<tbody>
|
|
13
|
+
<% @records.each do |record| %>
|
|
14
|
+
<tr>
|
|
15
|
+
<td><%= link_to 'Show', data_set_record_path(@data_set, record) %></td>
|
|
16
|
+
<td><%= link_to 'Edit', edit_data_set_record_path(@data_set, record) %></td>
|
|
17
|
+
<td><%= button_to 'Destroy', data_set_record_path(@data_set, record), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<% end %>
|
|
20
|
+
</tbody>
|
|
21
|
+
</table>
|
|
22
|
+
|
|
23
|
+
<br>
|
|
24
|
+
|
|
25
|
+
<%= link_to 'New Record', new_data_set_record_path(@data_set) %>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
|
2
|
+
|
|
3
|
+
<%= link_to 'Edit', edit_data_set_record_path(@data_set, @record) %> |
|
|
4
|
+
<%= link_to 'Back', data_set_records_path(@data_set) %>
|
|
5
|
+
|
|
6
|
+
<h2>Data set</h2>
|
|
7
|
+
<%= @record.data_set.name %>
|
|
8
|
+
|
|
9
|
+
<h2>Datos</h2>
|
|
10
|
+
|
|
11
|
+
<%= render @record %>
|
data/config/routes.rb
ADDED
data/config/spring.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Spring.application_root = './spec/dummy'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module TinOpener
|
|
2
|
+
class DataFileProcessor
|
|
3
|
+
def initialize(args = {})
|
|
4
|
+
@file = args.fetch(:file)
|
|
5
|
+
@separator = args.fetch(:separator) { ';' }
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def headers
|
|
9
|
+
@headers ||= rows.first.try do |row|
|
|
10
|
+
row.transform_values do |value|
|
|
11
|
+
value.class.name
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def rows
|
|
17
|
+
@csv_data ||= CSV.parse(@file, col_sep: @separator, headers: true).map do |row|
|
|
18
|
+
row.to_hash.transform_keys{ |a| a.squeeze.strip.gsub(/\s/, '_').underscore.to_sym }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module TinOpener
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace TinOpener
|
|
4
|
+
|
|
5
|
+
config.generators do |g|
|
|
6
|
+
g.test_framework :rspec, view_specs: false, controller_specs: false,
|
|
7
|
+
routing_specs: false, helper_specs: false, request_specs: false
|
|
8
|
+
g.integration_tool :rspec
|
|
9
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
|
10
|
+
|
|
11
|
+
g.stylesheets false
|
|
12
|
+
g.javascripts false
|
|
13
|
+
g.helper false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# config.paths.add "lib", eager_load: true
|
|
17
|
+
# config.paths.add "app", eager_load: true
|
|
18
|
+
# config.autoload_paths += Dir["#{config.root}/lib/**/"]
|
|
19
|
+
# config.autoload_paths += Dir["#{config.root}/app/**/"]
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/tin_opener.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
== README
|
|
2
|
+
|
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
|
4
|
+
application up and running.
|
|
5
|
+
|
|
6
|
+
Things you may want to cover:
|
|
7
|
+
|
|
8
|
+
* Ruby version
|
|
9
|
+
|
|
10
|
+
* System dependencies
|
|
11
|
+
|
|
12
|
+
* Configuration
|
|
13
|
+
|
|
14
|
+
* Database creation
|
|
15
|
+
|
|
16
|
+
* Database initialization
|
|
17
|
+
|
|
18
|
+
* How to run the test suite
|
|
19
|
+
|
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
|
21
|
+
|
|
22
|
+
* Deployment instructions
|
|
23
|
+
|
|
24
|
+
* ...
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|