scaffolding 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8671e3427494760d1568c7846a1728f05bd7eec5
4
- data.tar.gz: cfb03213051ffb7ccf930f4380ffa10be042985a
3
+ metadata.gz: 39f736ea24b0f039f8726314e93c0af29e24ad65
4
+ data.tar.gz: c57e952433bf79815c0664a5744c9916ad87c892
5
5
  SHA512:
6
- metadata.gz: 8cf10c9d7692cb5554ed704119f68e5f6475e80563c8154cbca6f98d1da1e3053c1db8dae485e9b76119e6efaeede7ecda16a407c0d4cb39e2e75f4aa679ed11
7
- data.tar.gz: b44127223ecc9063cb35d05135626cdb20330ebf7da09eee9998919c4555ded9c1b450456f8de467ef90701b57be224ac44a6365a7b9021052432e7def349304
6
+ metadata.gz: 4e7edf14eec9f001245d3bb655b9b73eeefa5df8c2556f1ac93ff5b35fc3fc64388b88e1133104c4ed3666194df077ae4bae1a213dbb58e0e6b2c2cf1ab1f6bb
7
+ data.tar.gz: c3af697d5c7c78e39fc5089aaa88180fa36abf978dabe2b7955475b50c78e8b260ec4ef712b0fcc275191ebf5460179314570d4cd10ef0fdd1862a42e206bb4e
data/README.md CHANGED
@@ -20,19 +20,34 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Ensure your file name is the same as the resource/model name you wish to generate.
23
+ $ rails g scaffolding [source] [name]
24
24
 
25
- $ rails g/generate scaffolding path/to/file.csv
25
+ You can pass either a path/to/the/file or a URL as the [source].
26
26
 
27
- Or
27
+ If a [name] is not passed, the scaffold will be named from the source:
28
+
29
+ $ rails g scaffolding path/to/file.csv
30
+
31
+ Will generate a scaffold named file
32
+
33
+ $ rails g scaffolding path/to/file.csv purchase_orders
34
+
35
+ Will generate a scaffold named purchase_orders
36
+
37
+
38
+ #### Multiple
39
+
40
+ To generate multiple scaffolds at the same time setup a scaffolding folder
28
41
 
29
42
  $ rake scaffolding:folder
30
43
 
31
44
  then add files to the 'tmp/scaffolding' directory and process them all with:
32
45
 
33
- $ rails g/generate scaffolding
46
+ $ rails g scaffolding
47
+
48
+ The scaffold's will be named the same as there respective files names.
34
49
 
35
- ### Options:
50
+ #### Options
36
51
  (You will be asked these at the terminal if not specified)
37
52
 
38
53
  Automatically determine the data types of each column:
@@ -6,21 +6,24 @@ require 'scaffolding'
6
6
  class ScaffoldingGenerator < Rails::Generators::Base
7
7
  desc "This generator generates a scaffold based on a CSV, Dat or Txt file and imports the data"
8
8
  argument :source, :type => :string, :default => ""
9
+ argument :name, :type => :string, :default => ""
9
10
  class_option :auto, :type => :boolean, :default => false, :description => "Automatically choose data types"
10
11
  class_option :migrate, :type => :boolean, :default => false, :description => "Migrate the database"
11
12
  class_option :import, :type => :boolean, :default => false, :description => "Import data from source"
12
13
 
13
14
  def analyize_sources
15
+ @source = source
16
+ @name = name
14
17
  @auto = options[:auto]
15
18
  @migrate = options[:migrate]
16
19
  @import = options[:import]
17
20
 
18
- if source == "" || source.nil?
21
+ if @source == "" || @source.nil?
19
22
  Dir[Rails.root.join('tmp/scaffolding/*')].each do |source|
20
- Scaffolding.generate(source, @auto, @migrate, @import)
23
+ Scaffolding.generate(source, @name, @auto, @migrate, @import)
21
24
  end
22
25
  else
23
- Scaffolding.generate(source, @auto, @migrate, @import)
26
+ Scaffolding.generate(@source, @name, @auto, @migrate, @import)
24
27
  end
25
28
  end
26
29
 
@@ -4,8 +4,9 @@ module Scaffolding
4
4
  require 'rails'
5
5
  require 'csv'
6
6
 
7
- def initialize(source="", auto, uri)
7
+ def initialize(source, name, auto, uri)
8
8
  @source = source
9
+ @name = name
9
10
  @auto = auto
10
11
  @uri = uri
11
12
  @errors = []
@@ -17,14 +18,22 @@ module Scaffolding
17
18
  def setup
18
19
  return unless @data = valid_data?
19
20
  @col_seperator = col_seperator
20
- @source_name = File.basename(@source, ".*" ).to_s.split.join.camelize.strip.singularize
21
- @scaffold_builder = @source_name
21
+ @source_name, @scaffold_builder = source_name
22
22
  end
23
23
 
24
24
  def errors
25
25
  @errors
26
26
  end
27
27
 
28
+ def source_name
29
+ if @name == ""
30
+ name = File.basename(@source, ".*")
31
+ else
32
+ name = @name.dup
33
+ end
34
+ name.to_s.downcase.split.join.camelize.strip.singularize
35
+ end
36
+
28
37
  def valid_data?
29
38
  if @source == "" || @source.nil?
30
39
  @errors << "No source selected"
@@ -105,8 +114,8 @@ module Scaffolding
105
114
  build_string
106
115
  end
107
116
 
108
- def self.process(source, auto, uri)
109
- importer = self.new(source, auto, uri)
117
+ def self.process(source, name, auto, uri)
118
+ importer = self.new(source, name, auto, uri)
110
119
  return importer.errors unless importer.errors.count == 0
111
120
  importer.results
112
121
  end
@@ -4,7 +4,7 @@ module Scaffolding
4
4
  ["Csv", "Raw"].each do |type|
5
5
  importer_class = Class.new("Scaffolding::Parser::#{type}".constantize) do
6
6
 
7
- def initialize(file="", auto, uri)
7
+ def initialize(source, name, auto, uri)
8
8
  super
9
9
  @saved = 0
10
10
  @failed = 0
@@ -1,3 +1,3 @@
1
1
  module Scaffolding
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/scaffolding.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require "scaffolding/version"
2
2
 
3
3
  module Scaffolding
4
- require 'scaffolding/railtie'
4
+ require 'scaffolding/railtie' if defined?(Rails)
5
5
  require 'uri'
6
6
 
7
- def self.generate(source, auto, migrate, import)
7
+ def self.generate(source, name, auto, migrate, import)
8
8
  @source = source
9
+ @name = name
9
10
  @auto = auto
10
11
  @migrate = migrate
11
12
  @import = import
@@ -23,7 +24,7 @@ module Scaffolding
23
24
  end
24
25
 
25
26
  def self.parser(namespace="")
26
- "Scaffolding::Parser#{namespace + "::" + Scaffolding.class_ref}".constantize.process(@source, @auto, @uri)
27
+ "Scaffolding::Parser#{namespace + "::" + Scaffolding.class_ref}".constantize.process(@source, @name, @auto, @uri)
27
28
  end
28
29
 
29
30
  def self.class_ref
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scaffolding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan-deJong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler