plant 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e46e6545f9cfda7072874f03013d7c242d32d525
4
+ data.tar.gz: a64ed6894a0c28cf1baf9c9c75305e16643fa4e6
5
+ SHA512:
6
+ metadata.gz: 32a9aeed5df45377abe04d501cf345519a48bf960309037258ac0894f20ad38640236298ad2e63cfadb5f0701ae1782695476f3b772c1252aa8093865768bef6
7
+ data.tar.gz: 4341dd1b68a628988918a2104d006794d968ac9d338275c8745e79a1948de4eeae7a2882330f01b51cac4f4abf869b94b636235137b583886374afe53832451f
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Plant
2
+
3
+ Dont just seed, plant.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Plant'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'spec'
27
+ t.pattern = 'spec/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ task default: :test
32
+ require 'rake/testtask'
@@ -0,0 +1,6 @@
1
+ # Helpers
2
+ module Plant
3
+ # Namespace application helper for writing to page
4
+ module ApplicationHelper
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+ module Plant
2
+ # Model for content
3
+ class Content < ActiveRecord::Base
4
+ # Gets the content for a given node
5
+ # => Parameter: node ID (string)
6
+ # => Parameter: scenario (optional)
7
+ # Can either by a string or an object with
8
+ # a scenario method, for example a user.
9
+ #
10
+ # If no specific scenario returned, then will
11
+ # default back to a nil scenario.
12
+ # Throws: NotFound if node not found
13
+ # => Returns: content for this node
14
+ def self.get_node_content(node, scenario = nil)
15
+ scenario = scenario.scenario if scenario.respond_to? :scenario
16
+ specific = where(node_id: "#{node}.#{scenario}").first
17
+ return specific.content if specific
18
+ find_by!(node_id: "#{node}.main").content
19
+ end
20
+
21
+ # Can only have one scenario-node_id combination
22
+ validates_uniqueness_of :scenario, scope: :node_id
23
+
24
+ before_validation :add_main
25
+
26
+ private
27
+
28
+ def add_main
29
+ append = scenario ? scenario : 'main'
30
+ self.node_id += ".#{append}" unless node_id.ends_with?(append)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ # Create content table
2
+ class CreatePlantContents < ActiveRecord::Migration
3
+ def change
4
+ create_table :plant_contents do |t|
5
+ t.string :node_id
6
+ t.text :content
7
+ t.string :scenario
8
+
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
data/lib/plant.rb CHANGED
@@ -1,5 +1,6 @@
1
- class Plant
2
- def initialize
3
- puts "CREATED NEW PLANT"
4
- end
1
+ require 'plant/hash_pathify'
2
+ require 'plant/engine'
3
+ require 'plant/utils'
4
+ # Main module
5
+ module Plant
5
6
  end
@@ -0,0 +1,13 @@
1
+ # Engine so we can mount it
2
+ module Plant
3
+ # Ensure the namespace is isolated
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Plant
6
+ config.generators do |g|
7
+ g.test_framework :rspec, fixture: false
8
+ g.fixture_replcement :factory_girl, dir: 'spec/factories'
9
+ g.assets false
10
+ g.helper false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # Monkey patch hash to provide pathify method
2
+ class Hash
3
+ # Returns a flat hash that show the full path to the
4
+ # value, so we don't have to recursively traverse a nested hash
5
+ # Examples:
6
+ # => {foo: 'ff'}.pathify
7
+ # => {foo: 'ff'}
8
+ # => {foo: {bar: 'gg', boo: 'hh'}}.pathify
9
+ # => {'foo/bar': 'gg', 'foo/boo': 'hh'}
10
+ # Optionally, Specify a seperator as first argument (defaults to '/')
11
+ def pathify(sep = '/', paths = [], path = '')
12
+ each do |key, value|
13
+ if value.is_a? Hash
14
+ value.pathify(sep, paths, "#{path}#{sep}#{key}")
15
+ else
16
+ paths << Hash["#{path}#{sep}#{key}".sub(/^#{sep}/, ''), value]
17
+ end
18
+ end
19
+ paths.reduce({}, :merge)
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ module Plant
2
+ # Utilities for the library
3
+ class Utils
4
+ # Gets all yml file in the given directory within the scope of a rails app
5
+ # Parameters dir (string) path reletive to Rails.root to search
6
+ # Returns Array of strings (filepaths)
7
+ def self.yaml_files(dir = 'app/content')
8
+ Dir.glob("#{Rails.root}/#{dir}/**/*.yml")
9
+ end
10
+
11
+ # Converts a given `path` yaml file into a flat hash of key: values
12
+ # Parameters path:string (path to yml file)
13
+ # Return Hash
14
+ def self.load_yaml_file(path)
15
+ contents = YAML.load(File.read(path))
16
+ return contents.pathify('.') if contents.respond_to? :pathify
17
+ {}
18
+ end
19
+
20
+ def self.load_all_yaml_files(dir = 'app/content')
21
+ Plant::Utils.yaml_files(dir).map do |fle|
22
+ Plant::Utils.load_yaml_file(fle)
23
+ end.reduce({}, :merge)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ # Version file
2
+ module Plant
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,11 @@
1
+ namespace :plant do
2
+ desc 'Puts the content from the YAML files into the database'
3
+ task populate: :environment do
4
+ puts 'Planting those seeds'
5
+ Plant::Utils.load_all_yaml_files.each do |full_node, value|
6
+ content_obj = Plant::Content.find_or_initialize_by(node_id: full_node)
7
+ content_obj.content = value.chomp
8
+ content_obj.save!
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,46 +1,209 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
- - Paul Brennan
7
+ - Yule
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-08-20 00:00:00.000000000 Z
13
- dependencies: []
14
- description: A seed replacement gem
15
- email: paul.brennan@ahc.com
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_girl_rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: reek
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: thor
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: A seed replacement. define your content in yml
168
+ email:
169
+ - paul.brennan@ahc.uk.com
16
170
  executables: []
17
171
  extensions: []
18
172
  extra_rdoc_files: []
19
173
  files:
174
+ - README.rdoc
175
+ - Rakefile
176
+ - app/helpers/plant/application_helper.rb
177
+ - app/models/plant/content.rb
178
+ - db/migrate/20150820134825_create_plant_contents.rb
20
179
  - lib/plant.rb
21
- homepage: http://rubygems.org/gems/plant
180
+ - lib/plant/engine.rb
181
+ - lib/plant/hash_pathify.rb
182
+ - lib/plant/utils.rb
183
+ - lib/plant/version.rb
184
+ - lib/tasks/plant_tasks.rake
185
+ homepage: http://www.dryule.com
22
186
  licenses:
23
187
  - MIT
188
+ metadata: {}
24
189
  post_install_message:
25
190
  rdoc_options: []
26
191
  require_paths:
27
192
  - lib
28
193
  required_ruby_version: !ruby/object:Gem::Requirement
29
- none: false
30
194
  requirements:
31
- - - ! '>='
195
+ - - ">="
32
196
  - !ruby/object:Gem::Version
33
197
  version: '0'
34
198
  required_rubygems_version: !ruby/object:Gem::Requirement
35
- none: false
36
199
  requirements:
37
- - - ! '>='
200
+ - - ">="
38
201
  - !ruby/object:Gem::Version
39
202
  version: '0'
40
203
  requirements: []
41
204
  rubyforge_project:
42
- rubygems_version: 1.8.23
205
+ rubygems_version: 2.4.6
43
206
  signing_key:
44
- specification_version: 3
45
- summary: Don't just seed, plant
207
+ specification_version: 4
208
+ summary: Don't just seed, plant.
46
209
  test_files: []