cascade-rb 0.1.2 → 0.1.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +72 -8
  3. data/lib/cascade/version.rb +1 -1
  4. metadata +1 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e7c151d9e2391755cff0beda2f782a240b9d2ad
4
- data.tar.gz: cf31282323bff8bc1c8f14125e758dbbd62a55d0
3
+ metadata.gz: fcc191b61c12c0765f47269758020be4aee60980
4
+ data.tar.gz: b5112f6db4896cf045c1b000c895c6b570ffb59b
5
5
  SHA512:
6
- metadata.gz: aa602951882137f43d3ba53173a592a0ff5c62354726ba3b4bca9ee8645aa64e5eb90e712d81b5ded63064fde8399c1b3a87854a9a91d532d1c5de75d0d62f69
7
- data.tar.gz: 976a18f137dc262bd9862ef366ca24f93211c40aaeb5b7418045557292ca06c337d7eb4ce2fda0d9c8c029c9df2f4c9a46d6f2e71da2dfd36c22717c2dd017a2
6
+ metadata.gz: dd6417644ca77d59c98ef1a90328753ac78e1e446fd598a4ac8325370adf7a96b3df37e2ef2dd1b77cc5348b9b4f86b44e7ce35f86908870e66e9df419eb9e17
7
+ data.tar.gz: 72ecd47503ee586f47f1ca5727ad500e36be2c12bed35a8fef63eb6d521f81733275a12e7952ea00fcf1d49c04f85dff901ad39c1c5844bce94209ec541ed65e
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # [Cascade]
2
2
 
3
- [![Codeship Status for ignat-zakrevsky/cascade](https://codeship.com/projects/d7590880-9943-0132-4aa6-1e41bc68e178/status?branch=master)](https://codeship.com/projects/63625) [![Code Climate](https://codeclimate.com/github/ignat-zakrevsky/cascade/badges/gpa.svg)](https://codeclimate.com/github/ignat-zakrevsky/cascade) [![Test Coverage](https://codeclimate.com/github/ignat-zakrevsky/cascade/badges/coverage.svg)](https://codeclimate.com/github/ignat-zakrevsky/cascade)
3
+ [![Codeship Status for ignat-zakrevsky/cascade](https://codeship.com/projects/d7590880-9943-0132-4aa6-1e41bc68e178/status?branch=master)](https://codeship.com/projects/63625) [![Code Climate](https://codeclimate.com/github/ignat-zakrevsky/cascade/badges/gpa.svg)](https://codeclimate.com/github/ignat-zakrevsky/cascade) [![Test Coverage](https://codeclimate.com/github/ignat-zakrevsky/cascade/badges/coverage.svg)](https://codeclimate.com/github/ignat-zakrevsky/cascade) [![Gem Version](https://badge.fury.io/rb/cascade-rb.svg)](http://badge.fury.io/rb/cascade-rb)
4
4
 
5
- The main aim of this repo is to provide some kind of template for parsers.
5
+ The main aim of this gem is to provide some kind of template for parsing files.
6
6
  Usually, parsing file process contains next steps:
7
7
 
8
8
  1. Retreiving info from file
@@ -15,11 +15,75 @@ Usually, parsing file process contains next steps:
15
15
 
16
16
  Cascade pretends to simplify main part of this step to save your time.
17
17
 
18
+ ## Example
19
+
20
+ [Working Example](https://github.com/ignat-zakrevsky/cascade-example)
21
+
22
+ ## Installation
23
+ Install the cascade-rb package from Rubygems:
24
+ ```
25
+ gem install cascade-rb
26
+ ```
27
+
28
+ or add it to your Gemfile for Bundler:
29
+ ```ruby
30
+ gem 'cascade-rb'
31
+ ```
32
+
18
33
  ## Usage
19
- - Configure database config
20
- `cp config/database.yml.sample config/database.yml`
21
- - Change `./config/columns_match.yml` to correspond your scheme
22
- - Create necessary ActiveRecord models
23
- - Add necessary parsers
24
- - Run it
34
+ Require gem files
35
+ ```ruby
36
+ require 'cascade'
37
+ ```
38
+
39
+ Configure it!
40
+ ```ruby
41
+ Cascade.configuration do
42
+ Cascade::RowProcessor.use_default_presenter = false # will throw exception in case of unavailable presenter
43
+ Cascade::ColumnsMatching.mapping_file = "columns_mapping.yml" # file with columns mapping, see below
44
+ end
45
+ ```
46
+
47
+ Provide file for parsing and run it!
48
+ ```ruby
49
+ Cascade::DataParser.new("data_test.txt").call
50
+ ```
51
+
52
+ ## Columns mapping
53
+ Parsing file description should have next structure [(example)](https://github.com/ignat-zakrevsky/cascade-example/blob/master/columns_mapping.yml)
54
+ ```yaml
55
+ mapping:
56
+ name: type
57
+ ```
25
58
 
59
+ ## Components replaceability
60
+ There is a lot of DI in this gem, so, you can replace each component of the parser. Let's assume you want to parse JSON files instead of CSV and save this to ActiveRecord model, ok!
61
+ Writing new data provider:
62
+ ```ruby
63
+ class ParserJSON
64
+ def open(file)
65
+ JSON.parse(File.read(file))["rows"]
66
+ end
67
+ end
68
+ ```
69
+ Writing new data saver:
70
+ ```ruby
71
+ class PersonDataSaver
72
+ def call(person_data)
73
+ Person.create!(person_data)
74
+ end
75
+ end
76
+ ```
77
+ considering that there is no much logic even better
78
+ ```ruby
79
+ PERSON_SAVER = -> (person_data) { Person.create!(person_data) }
80
+ ```
81
+ Provide it for data providing for data parser
82
+ ```ruby
83
+ Cascade::DataParser.new("data_test.json", data_saver: PERSON_SAVER,
84
+ data_provider: ParserJSON.new).call
85
+ ```
86
+ And that's all!
87
+ [Example](https://github.com/ignat-zakrevsky/cascade-example/blob/json-example/main.rb)
88
+ ## Conventions
89
+ I'm fan of callable object as consequence I prefer #call methods for classes with one responsibility. [Nice video](http://www.rubytapas.com/episodes/35-Callable) that describes benefits of such approach
@@ -1,4 +1,4 @@
1
1
  module Cascade
2
2
  # current gem version
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cascade-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignat Zakrevsky
@@ -189,7 +189,6 @@ files:
189
189
  - ".hound.yml"
190
190
  - ".ruby-style.yml"
191
191
  - Gemfile
192
- - Gemfile.lock
193
192
  - README.md
194
193
  - Rakefile
195
194
  - cascade.gemspec