Class: AbideDevUtils::Ppt::NewObjectBuilder
- Inherits:
-
Object
- Object
- AbideDevUtils::Ppt::NewObjectBuilder
- Defined in:
- lib/abide_dev_utils/ppt/new_obj.rb
Constant Summary collapse
- DEFAULT_EXT =
'.pp'
- VALID_EXT =
/(\.pp|\.rb)\.erb$/.freeze
- TMPL_PATTERN =
/^[a-zA-Z][^\s]*\.erb$/.freeze
- OBJ_PREFIX =
/^(c-|d-)/.freeze
- PREFIX_TEST_PATH =
{ 'c-' => 'classes', 'd-' => 'defines' }.freeze
Instance Attribute Summary collapse
-
#obj_name ⇒ Object
readonly
Returns the value of attribute obj_name.
-
#obj_path ⇒ Object
readonly
Returns the value of attribute obj_path.
-
#obj_type ⇒ Object
readonly
Returns the value of attribute obj_type.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#tmpl_data ⇒ Object
readonly
Returns the value of attribute tmpl_data.
-
#tmpl_dir ⇒ Object
readonly
Returns the value of attribute tmpl_dir.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(obj_type, obj_name, opts: {}, vars: {}) ⇒ NewObjectBuilder
constructor
A new instance of NewObjectBuilder.
-
#method_missing(method, *args, &block) ⇒ Object
If a method gets called on the Hiera object which is not defined, this sends that method call to hash, then doc, then super.
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Checks the respond_to? of hash, doc, or super.
Constructor Details
#initialize(obj_type, obj_name, opts: {}, vars: {}) ⇒ NewObjectBuilder
Returns a new instance of NewObjectBuilder.
18 19 20 21 22 23 24 25 26 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 18 def initialize(obj_type, obj_name, opts: {}, vars: {}) @obj_type = obj_type @obj_name = namespace_format(obj_name) @opts = opts @vars = vars class_vars validate_class_vars @tmpl_data = template_data(@opts.fetch(:tmpl_name, @obj_type)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
If a method gets called on the Hiera object which is not defined, this sends that method call to hash, then doc, then super.
40 41 42 43 44 45 46 47 48 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 40 def method_missing(method, *args, &block) return true if ['exist?', 'exists?'].include?(method.to_s) return @hash.send(method, *args, &block) if @hash.respond_to?(method) return @doc.send(method, *args, &block) if @doc.respond_to?(method) super(method, *args, &block) end |
Instance Attribute Details
#obj_name ⇒ Object (readonly)
Returns the value of attribute obj_name.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def obj_name @obj_name end |
#obj_path ⇒ Object (readonly)
Returns the value of attribute obj_path.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def obj_path @obj_path end |
#obj_type ⇒ Object (readonly)
Returns the value of attribute obj_type.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def obj_type @obj_type end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def root_dir @root_dir end |
#tmpl_data ⇒ Object (readonly)
Returns the value of attribute tmpl_data.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def tmpl_data @tmpl_data end |
#tmpl_dir ⇒ Object (readonly)
Returns the value of attribute tmpl_dir.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def tmpl_dir @tmpl_dir end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
28 29 30 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 28 def vars @vars end |
Instance Method Details
#build ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 30 def build force = @opts.fetch(:force, false) obj_cont = force ? true : continue?(obj_path) spec_cont = force ? true : continue?(@tmpl_data[:spec_path]) write_file(obj_path, @tmpl_data[:path]) if obj_cont write_file(@tmpl_data[:spec_path], @spec_tmpl) if spec_cont end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Checks the respond_to? of hash, doc, or super
51 52 53 54 55 |
# File 'lib/abide_dev_utils/ppt/new_obj.rb', line 51 def respond_to_missing?(method_name, include_private = false) return true if ['exist?', 'exists?'].include?(method_name.to_s) @hash || @doc || super end |