Class: Crudboy::Bundle
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#context ⇒ Object
Returns the value of attribute context.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#path ⇒ Object
Returns the value of attribute path.
-
#result ⇒ Object
Returns the value of attribute result.
-
#templates ⇒ Object
Returns the value of attribute templates.
Instance Method Summary collapse
-
#initialize(path, options, destination, context) ⇒ Bundle
constructor
A new instance of Bundle.
- #initialize_path(path) ⇒ Object
- #initialize_templates ⇒ Object
- #load_initializer! ⇒ Object
- #load_option_definitions ⇒ Object
- #parse_options(options) ⇒ Object
- #render! ⇒ Object
Constructor Details
#initialize(path, options, destination, context) ⇒ Bundle
Returns a new instance of Bundle.
48 49 50 51 52 53 54 55 |
# File 'lib/crudboy/bundle.rb', line 48 def initialize(path, , destination, context) @path = initialize_path(path) @destination = destination @options = () @context = context @context. = @options @templates = initialize_templates end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/crudboy/bundle.rb', line 7 def config @config end |
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/crudboy/bundle.rb', line 7 def context @context end |
#destination ⇒ Object
Returns the value of attribute destination.
7 8 9 |
# File 'lib/crudboy/bundle.rb', line 7 def destination @destination end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/crudboy/bundle.rb', line 7 def path @path end |
#result ⇒ Object
Returns the value of attribute result.
7 8 9 |
# File 'lib/crudboy/bundle.rb', line 7 def result @result end |
#templates ⇒ Object
Returns the value of attribute templates.
7 8 9 |
# File 'lib/crudboy/bundle.rb', line 7 def templates @templates end |
Instance Method Details
#initialize_path(path) ⇒ Object
9 10 11 12 |
# File 'lib/crudboy/bundle.rb', line 9 def initialize_path(path) # TODO path end |
#initialize_templates ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/crudboy/bundle.rb', line 63 def initialize_templates templates_path= File.join(@path, 'templates') Find.find(templates_path).map do |file_path| base_path = file_path.delete_prefix(templates_path) Template.new(file_path, base_path, @context) end end |
#load_initializer! ⇒ Object
57 58 59 60 61 |
# File 'lib/crudboy/bundle.rb', line 57 def load_initializer! "#{@path}/init.rb".tap do |initializer_file| load(initializer_file) if File.exist?(initializer_file) end end |
#load_option_definitions ⇒ Object
42 43 44 45 46 |
# File 'lib/crudboy/bundle.rb', line 42 def load_option_definitions File.join(@path, "options.rb").try do |option_definitions_file| load(option_definitions_file) end end |
#parse_options(options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/crudboy/bundle.rb', line 14 def () load_option_definitions return unless Object::const_defined?('TEMPLATE_OPTIONS') OpenStruct.new.tap do |result| TEMPLATE_OPTIONS.each do |definition| definition[:default].try do |default| result[definition[:name]] = default end end OptionParser.new do |opts| opts. = "Template Options:\n\n" TEMPLATE_OPTIONS.each do |definition| opts.on(*definition.values_at(:short, :long, :description)) do |value| result[definition[:name]] = value end end opts.on('', '--help', 'Prints this help') do puts opts exit end end.parse!() end end |
#render! ⇒ Object
71 72 73 74 75 76 |
# File 'lib/crudboy/bundle.rb', line 71 def render! load_initializer! templates.each do |template| template.render!(@destination) end end |